我已經想出瞭如何使用Zend Gdata對地址進行地理編碼,但我甚至不知道如何檢索返回的JSON片斷。這裏是地址解析器:使用Zend Gdata創建Google地圖
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" })
真的我想使用該數據來創建分割地圖,一個正常的與標誌物和拆分視圖顯示街景。有什麼建議麼?
謝謝你,現在我該如何獲得位置:緯度和長度從結果數據。其顯示如:stdClass Object([lat] => 38.900063880291 [lng] => -77.036306519708)[southwest] => stdClass Object([lat] => 38.897365919709 [lng] => -77.039004480291)))[partial_match] => 1 [types] => Array([0] => street_address)))[status] =>確定) – savagenoob 2012-01-30 04:07:11
您現在已將數據添加到地圖中,這裏是google maps javascript api tutorial [Google Maps JavaScript API V3 ](http://code.google.com/apis/maps/documentation/javascript/tutorial.html) – RockyFord 2012-01-30 04:46:07