Создайте карту Google с помощью Zend Gdata - PullRequest
2 голосов
/ 30 января 2012

Я выяснил, как геокодировать адрес с помощью Zend Gdata, но я даже не знаю, как получить возвращенные фрагменты JSON.Вот геокодер:

include_once('Zend/Gdata.php');
$client = new Zend_Http_Client('http://maps.googleapis.com/maps/api/geocode/json');

$urlencodedAddress = urlencode('1600 Pennsylvania Avenue, N.W. Washington, DC 20500');

$client->setParameterGet('sensor', 'false');
$client->setParameterGet('address', $urlencodedAddress); 
$response = $client->request('GET');    

, а вот объект ответа:

Zend_Http_Response Object ( [version:protected] => 1.1 [code:protected] => 200 [message:protected] => OK [headers:protected] => Array ( [Content-type] => application/json; charset=UTF-8 [Date] => Mon, 30 Jan 2012 03:26:25 GMT [Expires] => Tue, 31 Jan 2012 03:26:25 GMT [Cache-control] => public, max-age=86400 [Vary] => Accept-Language [Server] => mafe [X-xss-protection] => 1; mode=block [X-frame-options] => SAMEORIGIN [Connection] => close ) [body:protected] => { "results" : [ { "address_components" : [ { "long_name" : "1600", "short_name" : "1600", "types" : [ "street_number" ] }, { "long_name" : "Pennsylvania Ave NW", "short_name" : "Pennsylvania Ave NW", "types" : [ "route" ] }, { "long_name" : "Northwest Washington", "short_name" : "Northwest Washington", "types" : [ "neighborhood", "political" ] }, { "long_name" : "Washington", "short_name" : "Washington", "types" : [ "locality", "political" ] }, { "long_name" : "District of Columbia", "short_name" : "DC", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "20500", "short_name" : "20500", "types" : [ "postal_code" ] } ], "formatted_address" : "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", "geometry" : { "location" : { "lat" : 38.89871490, "lng" : -77.03765550 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 38.90006388029150, "lng" : -77.03630651970849 }, "southwest" : { "lat" : 38.89736591970851, "lng" : -77.03900448029150 } } }, "partial_match" : true, "types" : [ "street_address" ] } ], "status" : "OK" } )

На самом деле я хотел бы использовать данные для создания карты раскола, обычной с маркероми разделенный вид, показывающий вид на улицу.Какие-либо предложения?

Ответы [ 2 ]

2 голосов
/ 30 января 2012

Вы можете сделать это

// get json object 
json_decode($response->getBody());

Ссылки.http://framework.zend.com/manual/en/zend.http.response.html

0 голосов
/ 30 января 2012

Действительно, ответ - забудь об этом Зенд. Что за трата времени. Намного проще сделать:

$urlencodedAddress = urlencode('1600 Pennsylvania Avenue, N.W. Washington, DC 20500');

$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $urlencodedAddress . "&sensor=false";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geoloc = json_decode(curl_exec($ch), true);


var_dump($geoloc['results'][0]['geometry']['location']['lat']);
var_dump($geoloc['results'][0]['geometry']['location']['lng']);

cUrl мой лучший друг.

...