static function geocode($place, $country = '') { $text = $country ? $place . ',' . $country : $place; $temp = TempStore::getInstance(); $key = 'YahooQueryClient/geocode//' . $text; $data = $temp->get($key); if ($data) { return unserialize($data); } $q = urlencode('select * from geo.places where text="' . $text . '"'); $url = 'http://query.yahooapis.com/v1/public/yql?q=' . $q . '&format=json'; $x = Json::decode($url); //XXX: instead return all results as array of YahooGeocodeResult objects? if ($x->query->count > 1) { $item = $x->query->results->place[0]; } else { $item = $x->query->results->place; } $res = new YahooGeocodeResult(); $res->name = $item->name; $res->country = $item->country->code; /* XXX TODO: parse admin1, admin2: admin1: { * code: "" * type: "County" * content: "Jamtland" } admin2: { * code: "" * type: "Municipality" * content: "Härjedalen" } */ $res->woeid = $item->woeid; $res->area = new \StdClass(); $res->area->center = new YahooQueryCoordinate($item->centroid->latitude, $item->centroid->longitude); $res->area->sw = new YahooQueryCoordinate($item->boundingBox->southWest->latitude, $item->boundingBox->southWest->longitude); $res->area->ne = new YahooQueryCoordinate($item->boundingBox->northEast->latitude, $item->boundingBox->northEast->longitude); //XXX this is a ugly hack until yahoo returns timezone with their response $geoname = GeonamesClient::reverse($item->centroid->latitude, $item->centroid->longitude); $res->timezone = $geoname->timezone; $temp->set($key, serialize($res)); return $res; }
public static function get($latitude, $longitude) { /* $temp = TempStore::getInstance(); $key = 'GeoLookupClient//'.$latitude.'/'.$longitude; $data = $temp->get($key); if ($data) return unserialize($data); */ $geonames = GeonamesClient::reverse($latitude, $longitude); // $google = GoogleMapsClient::reverse($latitude, $longitude); // return a combination of data from both sources because neither returns all we want alone $res = new GeoLookupResult(); // $res->description = $google->description; // $res->accuracy = $google->accuracy; $res->country_code = $geonames->country_code; $res->country_name = $geonames->country_name; $res->timezone = $geonames->timezone; $res->sunrise = $geonames->sunrise; $res->sunset = $geonames->sunset; // $temp->set($key, serialize($res), '1h'); return $res; }