/** * Populate this object * @since Version 3.9.1 * * @param string $country * @param string $region * * @return void */ private function load($country, $region) { if (filter_var($country, FILTER_VALIDATE_INT)) { // We're looking up a WoE ID $woe = $this->fetchWoE($country, $region); $country = $woe['country attrs']['code']; $region = str_replace($country . "-", "", $woe['admin1 attrs']['code']); $this->Country = Factory::CreateCountry($country); } /* $query = "SELECT DISTINCT country_name, region_name FROM geoplace WHERE country_code = ? AND region_code = ?"; $result = $this->db->fetchRow($query, array( strtoupper($country), strtoupper($region) )); list ( $country_name, $region_name ) = $result; */ /** * Fetch the WOE (Where On Earth) data from Yahoo */ if (!isset($woe)) { $this->Country = Factory::CreateCountry($country); $woe = $this->fetchWoE($this->Country->code, $region); } //if (empty($this->Country->name) && !preg_match("@[a-zA-Z]+@", $country) && isset($woe['country'])) { // $this->Country = Factory::CreateCountry($woe['country']); //} #$regions = ISO_3166::regions_by_country($country); $this->code = strtoupper($region); $this->name = ISO_3166::getRegionName($this->Country->code, $region); $this->url = new Url(sprintf("%s/%s", $this->Country->url, $this->slug)); $this->centre = new stdClass(); $this->centre->lat = $woe['centroid']['latitude']; $this->centre->lon = $woe['centroid']['longitude']; $this->boundingBox = new stdClass(); $this->boundingBox->northEast = new stdClass(); $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude']; $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude']; $this->boundingBox->southWest = new stdClass(); $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude']; $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude']; if (isset($woe['timezone'])) { $this->timezone = $woe['timezone']; } if (empty($this->name)) { $this->name = ucwords(strtolower(str_replace("-", " ", $this->code))); } }
/** * 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']); }