使用 Zend Gdata 创建 Google 地图
我已经弄清楚如何使用 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" } )
我真的想使用数据来创建一张分割地图,一个带有标记的普通地图和一个显示街景的分割视图。有什么建议吗?
I have figured out how to geocode an address using Zend Gdata, but I dont even know how to retrieve the pieces of JSON returned. Here is the geocoder:
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');
and here is the response object:
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" } )
Really I would like to use the data to create a split map, a normal one with a marker and a split view showing the streetview. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做
参考文献。 http://framework.zend.com/manual/en/zend.http .response.html
You could do this
References. http://framework.zend.com/manual/en/zend.http.response.html
确实,答案是忘记 Zend。真是浪费时间。做起来简单多了:
cUrl 是我最好的朋友。
Really, the answer is forget Zend for this. What a waste of time. So much simpler to do:
cUrl is my best friend.