Пример #1
0
 /**
  * Populate this object
  * @since Version 3.9.1
  * @return void
  */
 private function load()
 {
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     $woe = $this->getWOEData($this->lat . "," . $this->lon);
     if (!isset($woe['places']['place'][0])) {
         throw new Exception("Could not find a place matching coordinates " . $this->lat . "," . $this->lon);
     }
     /**
      * Simple enough - create the country object
      */
     $this->Country = LocationsFactory::CreateCountry($woe['places']['place'][0]['country']);
     /**
      * Bit trickier - find the region, ie, the next geographical location down from a country
      */
     foreach ($woe['places']['place'][0] as $key => $val) {
         if (isset($val['type']) && strtolower($val['type']) != "country") {
             $this->Region = LocationsFactory::CreateRegion($val['woeid']);
             break;
         }
     }
     /**
      * Set the place name
      */
     if (empty($this->name)) {
         $this->name = $woe['places']['place'][0]['locality1'];
     }
     /**
      * Set the bounding box
      */
     $this->boundingBox = new stdClass();
     $this->boundingBox->northEast = new stdClass();
     $this->boundingBox->northEast->lat = floatval($woe['places']['place'][0]['boundingBox']['northEast']['latitude']);
     $this->boundingBox->northEast->lon = floatval($woe['places']['place'][0]['boundingBox']['northEast']['longitude']);
     $this->boundingBox->southWest = new stdClass();
     $this->boundingBox->southWest->lat = floatval($woe['places']['place'][0]['boundingBox']['southWest']['latitude']);
     $this->boundingBox->southWest->lon = floatval($woe['places']['place'][0]['boundingBox']['southWest']['longitude']);
 }