/** * Set the geocode data for this location * @since Version 3.9.1 * @return void */ private function geocode() { if (!empty($this->region) && !empty($this->country) && !empty($this->locality)) { #return; } $woe = PlaceUtility::LatLonWoELookup($this->lat, $this->lon); $woe = PlaceUtility::formatWoE($woe); $this->country = $woe['country_code']; $this->region = $woe['region_code']; $this->locality = $woe['neighbourhood']; $this->neighbourhood = null; // $this->neighbourhood is ignored if (empty($this->region)) { $this->region = $woe['region']; } /** * Shit's a little bit broken, it's ok */ if (empty($this->region) || empty($this->country)) { $woe = PlaceUtility::LatLonWoELookup($this->lat, $this->lon, true); // force lookup, ignore any cached data $woe = PlaceUtility::formatWoE($woe); $this->region = $woe['region_code']; $this->country = $woe['country_code']; } if (empty($this->region)) { $this->region = strtoupper($woe['region_name']); } #printArray($this->region);die; return; /* // Fetch geodata and populate the vars //$url = "http://maps.google.com/maps/geo?q=".$this->lat.",".$this->lon."&output=json&sensor=false"; $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" . $this->lat . "," . $this->lon . "&sensor=false"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $jsondata = json_decode($data, true); curl_close($ch); if (isset($jsondata['results'][0]['address_components'])) { $row = $jsondata['results'][0]['address_components']; } if (isset($jsondata['Placemark']) && $area = $jsondata['Placemark'][0]['AddressDetails']['Country']) { $this->country = $area['CountryNameCode']; $this->region = isset($area['AdministrativeArea']['AdministrativeAreaName']) ? $area['AdministrativeArea']['AdministrativeAreaName'] : NULL; $this->locality = isset($area['AdministrativeArea']['Locality']['LocalityName']) ? $area['AdministrativeArea']['Locality']['LocalityName'] : NULL; $this->neighbourhood = isset($area['CountryNameCode']['someotherarea']) ? $area['CountryNameCode']['someotherarea'] : NULL; } elseif (isset($row)) { // Loop through the results and try to populate the object foreach ($row as $area) { if ($area['types'][0] == "country") { $this->country = $area['short_name']; } if ($area['types'][0] == "administrative_area_level_2") { $this->region = $area['long_name']; } if ($area['types'][0] == "administrative_area_level_3") { $this->neighbourhood = $area['long_name']; } if ($area['types'][0] == "locality") { $this->locality = $area['long_name']; } } } if (empty($this->country) || empty($this->region) || empty($this->locality)) { // Google doesn't give data in a consistent bloody format - go here instead $url = sprintf("http://www.geoplugin.net/extras/location.gp?lat=%s&long=%s&format=php", $this->lat, $this->lon); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $geodata = curl_exec($ch); $geodata = unserialize($geodata); curl_close($ch); $this->country = $geodata['geoplugin_countryCode']; $this->region = $geodata['geoplugin_region']; $this->locality = $geodata['geoplugin_place']; $this->neighbourhood = NULL; } return; */ }