Exemple #1
0
 public function findLocationByLocationName($locationName)
 {
     //http://maps.google.com/maps/geo?q=Kiev%20/%20Kyiv,%20Ukraine&output=json&oe=utf8
     $client = new Rest\Client\RestClient();
     $client->setUri("http://maps.google.com");
     $client->setHeaders('Accept-Charset', 'ISO-8859-1,utf-8');
     $_query = array('q' => $locationName, 'output'=>'json', 'oe'=>'utf8');
     $response = $client->restGet('/maps/geo', $_query);
     $location = Json\Json::decode($response->getBody());
     if (empty($location->Placemark)) return null;
     $placemark = $location->Placemark;
     if (!count($placemark)) return null;
     $place = current($placemark);
     list($long, $lat) = $place->Point->coordinates;
     return new Location($lat, $long);
 }