谷歌地图API位置请求 Google maps api
以xml格式传回请求的地址:
文件样式:
This XML file does not appear to have any style information associated with it. The document tree is shown below.OK street_address 中国北京市东城区南池子大街128号 128号 128号 street_number 南池子大街 南池子大街 route 东城区 东城区 sublocality political 北京 北京 locality political 北京市 北京市 administrative_area_level_1 political 中国 CN country political 39.9102420 116.4039110 ROOFTOP 39.9088930 116.4025620 39.9115910 116.4052600 bus_station transit_station establishment 中国北京市东城区皇史宬 皇史宬站 皇史宬站 bus_station transit_station establishment 东城区 东城区 sublocality political 北京 北京 locality political 北京市 北京市 administrative_area_level_1 political 中国 CN country political 39.9099750 116.4032030 APPROXIMATE 39.9086260 116.4018540 39.9113240 116.4045520 sublocality political 中国北京市东城区 东城区 东城区 sublocality political 北京 北京 locality political 北京市 北京市 administrative_area_level_1 political 中国 CN country political 39.9281310 116.4163940 APPROXIMATE 39.8586253 116.3771342 39.9740367 116.4523907 39.8586253 116.3771342 39.9740367 116.4523907 administrative_area_level_1 political 中国北京市 北京市 北京市 administrative_area_level_1 political 中国 CN country political 39.9042140 116.4074130 APPROXIMATE 39.4427581 115.4234115 41.0608158 117.5146251 39.4427581 115.4234115 41.0608158 117.5146251 locality political 中国北京市 北京 北京 locality political 北京市 北京市 administrative_area_level_1 political 中国 CN country political 39.9042140 116.4074130 APPROXIMATE 39.6612714 116.0119343 40.2164962 116.7829835 39.4427581 115.4234115 41.0608158 117.5146251 country political 中国 中国 CN country political 35.8616600 104.1953970 APPROXIMATE 18.1535216 73.4994137 53.5609740 134.7728100 18.1535216 73.4994137 53.5609740 134.7728100
以json格式传回请求的地址:
文件样式:
{ "results" : [ { "address_components" : [ { "long_name" : "128号", "short_name" : "128号", "types" : [ "street_number" ] }, { "long_name" : "南池子大街", "short_name" : "南池子大街", "types" : [ "route" ] }, { "long_name" : "东城区", "short_name" : "东城区", "types" : [ "sublocality", "political" ] }, { "long_name" : "北京", "short_name" : "北京", "types" : [ "locality", "political" ] }, { "long_name" : "北京市", "short_name" : "北京市", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国北京市东城区南池子大街128号", "geometry" : { "location" : { "lat" : 39.9102420, "lng" : 116.4039110 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 39.91159098029149, "lng" : 116.4052599802915 }, "southwest" : { "lat" : 39.90889301970849, "lng" : 116.4025620197085 } } }, "types" : [ "street_address" ] }, { "address_components" : [ { "long_name" : "皇史宬站", "short_name" : "皇史宬站", "types" : [ "bus_station", "transit_station", "establishment" ] }, { "long_name" : "东城区", "short_name" : "东城区", "types" : [ "sublocality", "political" ] }, { "long_name" : "北京", "short_name" : "北京", "types" : [ "locality", "political" ] }, { "long_name" : "北京市", "short_name" : "北京市", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国北京市东城区皇史宬", "geometry" : { "location" : { "lat" : 39.9099750, "lng" : 116.4032030 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 39.91132398029149, "lng" : 116.4045519802915 }, "southwest" : { "lat" : 39.90862601970849, "lng" : 116.4018540197085 } } }, "types" : [ "bus_station", "transit_station", "establishment" ] }, { "address_components" : [ { "long_name" : "东城区", "short_name" : "东城区", "types" : [ "sublocality", "political" ] }, { "long_name" : "北京", "short_name" : "北京", "types" : [ "locality", "political" ] }, { "long_name" : "北京市", "short_name" : "北京市", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国北京市东城区", "geometry" : { "bounds" : { "northeast" : { "lat" : 39.97403670, "lng" : 116.45239070 }, "southwest" : { "lat" : 39.85862530, "lng" : 116.37713420 } }, "location" : { "lat" : 39.9281310, "lng" : 116.4163940 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 39.97403670, "lng" : 116.45239070 }, "southwest" : { "lat" : 39.85862530, "lng" : 116.37713420 } } }, "types" : [ "sublocality", "political" ] }, { "address_components" : [ { "long_name" : "北京市", "short_name" : "北京市", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国北京市", "geometry" : { "bounds" : { "northeast" : { "lat" : 41.06081580, "lng" : 117.51462510 }, "southwest" : { "lat" : 39.44275810, "lng" : 115.42341150 } }, "location" : { "lat" : 39.9042140, "lng" : 116.4074130 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 41.06081580, "lng" : 117.51462510 }, "southwest" : { "lat" : 39.44275810, "lng" : 115.42341150 } } }, "types" : [ "administrative_area_level_1", "political" ] }, { "address_components" : [ { "long_name" : "北京", "short_name" : "北京", "types" : [ "locality", "political" ] }, { "long_name" : "北京市", "short_name" : "北京市", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国北京市", "geometry" : { "bounds" : { "northeast" : { "lat" : 41.06081580, "lng" : 117.51462510 }, "southwest" : { "lat" : 39.44275810, "lng" : 115.42341150 } }, "location" : { "lat" : 39.9042140, "lng" : 116.4074130 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 40.21649620, "lng" : 116.78298350 }, "southwest" : { "lat" : 39.66127140, "lng" : 116.01193430 } } }, "types" : [ "locality", "political" ] }, { "address_components" : [ { "long_name" : "中国", "short_name" : "CN", "types" : [ "country", "political" ] } ], "formatted_address" : "中国", "geometry" : { "bounds" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.772810 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941369999999 } }, "location" : { "lat" : 35.861660, "lng" : 104.1953970 }, "location_type" : "APPROXIMATE", "viewport" : { "northeast" : { "lat" : 53.56097399999999, "lng" : 134.772810 }, "southwest" : { "lat" : 18.15352160, "lng" : 73.49941369999999 } } }, "types" : [ "country", "political" ] } ], "status" : "OK"}
http://maps.google.com/maps/api/geocode/xml(或者json)?latlng=39.910093,116.403945&language=zh-CN&sensor=false
Google Geocoding API 参数,所有参数均使用&(and)符号分隔。枚举参数可能的值:latlng(必须)- 您希望获取的、距离最近的、可人工读取地址的纬度/经度文本值(leg:latlng=39.910093,116.403945)
bounds(可选)- 要在其中更显著地偏移地址解析结果的可视区域的边框。region(可选)- 区域代码,指定为ccTLD(“顶级域”)双字符值。language(可选) - 传回结果时所使用的语言。请注意,我们会经常更新支持的语言,因此该列表可能并不想尽。如果未提供language,地址解析协议将尝试尽可能使用发送请求的区域本地语言。sensor(必须)- 指示地址解析请求是否来自装有位置传感器的设备。该值必须为true或false。
注意:bounds和region参数只会影响地址解析器返回的结果,但不能对其进行完全限制。处理响应结果:
1:判断 status的状态信息。
2:获取 formatted_address 地址信息。
注意:formatted_address 是一个字符串,包含此位置的人类可读地址。通常该地址相当于“邮政地址”,有时会因不同国家/地区而出现差异。注: “status”字段可能包含以下值:
“OK” 表示未发生错误;地址成功进行了解析并且至少传回了一个地址解析结果(判断请求是否成功响应)
“ZERO_RESULTS”表示地址解析成功,但未返回结果。如果地址解析过程中传递的偏远位置 address或latlng 并不存在,则会出现这种情况。“OVER_QUERY_LIMIT” 表示您超出了配额。“REQUEST_DENIED”表示您的请求被拒绝,通常是由于缺少sensor参数。“INVALID_REQUEST”通常表示缺少查询参数(address或latlng)。