谷歌地图API位置请求_Google Maps API

谷歌地图API位置请求  Google maps api

以xml格式传回请求的地址:http://maps.google.com/maps/api/geocode/xml?latlng=39.910093,116.403945&language=zh-CN&sensor=false

文件样式:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<GeocodeResponse>
<status>OK</status>
<result>
<type>street_address</type>
<formatted_address>中国北京市东城区南池子大街128号</formatted_address>
<address_component>
<long_name>128号</long_name>
<short_name>128号</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>南池子大街</long_name>
<short_name>南池子大街</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>东城区</long_name>
<short_name>东城区</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京</long_name>
<short_name>北京</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京市</long_name>
<short_name>北京市</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>39.9102420</lat>
<lng>116.4039110</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>39.9088930</lat>
<lng>116.4025620</lng>
</southwest>
<northeast>
<lat>39.9115910</lat>
<lng>116.4052600</lng>
</northeast>
</viewport>
</geometry>
</result>
<result>
<type>bus_station</type>
<type>transit_station</type>
<type>establishment</type>
<formatted_address>中国北京市东城区皇史宬</formatted_address>
<address_component>
<long_name>皇史宬站</long_name>
<short_name>皇史宬站</short_name>
<type>bus_station</type>
<type>transit_station</type>
<type>establishment</type>
</address_component>
<address_component>
<long_name>东城区</long_name>
<short_name>东城区</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京</long_name>
<short_name>北京</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京市</long_name>
<short_name>北京市</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>39.9099750</lat>
<lng>116.4032030</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>39.9086260</lat>
<lng>116.4018540</lng>
</southwest>
<northeast>
<lat>39.9113240</lat>
<lng>116.4045520</lng>
</northeast>
</viewport>
</geometry>
</result>
<result>
<type>sublocality</type>
<type>political</type>
<formatted_address>中国北京市东城区</formatted_address>
<address_component>
<long_name>东城区</long_name>
<short_name>东城区</short_name>
<type>sublocality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京</long_name>
<short_name>北京</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京市</long_name>
<short_name>北京市</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>39.9281310</lat>
<lng>116.4163940</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>39.8586253</lat>
<lng>116.3771342</lng>
</southwest>
<northeast>
<lat>39.9740367</lat>
<lng>116.4523907</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>39.8586253</lat>
<lng>116.3771342</lng>
</southwest>
<northeast>
<lat>39.9740367</lat>
<lng>116.4523907</lng>
</northeast>
</bounds>
</geometry>
</result>
<result>
<type>administrative_area_level_1</type>
<type>political</type>
<formatted_address>中国北京市</formatted_address>
<address_component>
<long_name>北京市</long_name>
<short_name>北京市</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>39.9042140</lat>
<lng>116.4074130</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>39.4427581</lat>
<lng>115.4234115</lng>
</southwest>
<northeast>
<lat>41.0608158</lat>
<lng>117.5146251</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>39.4427581</lat>
<lng>115.4234115</lng>
</southwest>
<northeast>
<lat>41.0608158</lat>
<lng>117.5146251</lng>
</northeast>
</bounds>
</geometry>
</result>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>中国北京市</formatted_address>
<address_component>
<long_name>北京</long_name>
<short_name>北京</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>北京市</long_name>
<short_name>北京市</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>39.9042140</lat>
<lng>116.4074130</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>39.6612714</lat>
<lng>116.0119343</lng>
</southwest>
<northeast>
<lat>40.2164962</lat>
<lng>116.7829835</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>39.4427581</lat>
<lng>115.4234115</lng>
</southwest>
<northeast>
<lat>41.0608158</lat>
<lng>117.5146251</lng>
</northeast>
</bounds>
</geometry>
</result>
<result>
<type>country</type>
<type>political</type>
<formatted_address>中国</formatted_address>
<address_component>
<long_name>中国</long_name>
<short_name>CN</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>35.8616600</lat>
<lng>104.1953970</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>18.1535216</lat>
<lng>73.4994137</lng>
</southwest>
<northeast>
<lat>53.5609740</lat>
<lng>134.7728100</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>18.1535216</lat>
<lng>73.4994137</lng>
</southwest>
<northeast>
<lat>53.5609740</lat>
<lng>134.7728100</lng>
</northeast>
</bounds>
</geometry>
</result>
</GeocodeResponse>

 

以json格式传回请求的地址: http://maps.google.com/maps/api/geocode/json?latlng=39.910093,116.403945&language=zh-CN&sensor=false

文件样式:

{
   "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)。

posted @ 2012-07-14 00:04  Vito.K  阅读(2455)  评论(2编辑  收藏  举报