Google maps api 3 如何通过向谷歌地图api提供一个城市来找出相应的国家和地区

Google maps api 3 如何通过向谷歌地图api提供一个城市来找出相应的国家和地区,google-maps-api-3,geolocation,Google Maps Api 3,Geolocation,我正在创建一个天气应用程序,我需要知道一个城市的国家和地区,以提供天气数据。当用户搜索某个城市时,应用程序会显示一个具有该名称的所有城市以及国家和地区的列表 谷歌地图API是否可以实现这一点,或者是否有更好的选择?我建议使用谷歌地理编码API的组件参数。在下面的示例中,我查询的是所有名为莫斯科的地方(城市、未合并地区和其他命名的人口聚集地)。您可以在XML输出中看到,它同时包含俄罗斯莫斯科和爱达荷州莫斯科。输出还包括国家和一级行政区划(例如,美国的州)(见) https://maps.googl

我正在创建一个天气应用程序,我需要知道一个城市的国家和地区,以提供天气数据。当用户搜索某个城市时,应用程序会显示一个具有该名称的所有城市以及国家和地区的列表


谷歌地图API是否可以实现这一点,或者是否有更好的选择?

我建议使用谷歌地理编码API的组件参数。在下面的示例中,我查询的是所有名为莫斯科的地方(城市、未合并地区和其他命名的人口聚集地)。您可以在XML输出中看到,它同时包含俄罗斯莫斯科和爱达荷州莫斯科。输出还包括国家和一级行政区划(例如,美国的州)(见)

https://maps.googleapis.com/maps/api/geocode/xml?address=component:locality=Moscow&sensor=false
好啊
地点
政治的
俄罗斯莫斯科
莫斯科
莫斯科
地点
政治的
哥罗德莫斯科
G莫斯科
行政区二级
政治的
莫斯科
莫斯科
行政区一级
政治的
俄罗斯联邦
茹
国
政治的
55.7558260
37.6173000
近似
55.4899270
37.3193290
56.0096570
37.9456610
55.4899270
37.3193290
56.0096570
37.9456610
符合事实的
地点
政治的
莫斯科,ID,美国
莫斯科
莫斯科
地点
政治的
拉塔
拉塔
行政区二级
政治的
爱达荷州
身份证件
行政区一级
政治的
美国
我们
国
政治的
46.7323875
-117.0001651
近似
46.7109120
-117.0396980
46.7588820
-116.9620680
46.7109120
-117.0396980
46.7588820
-116.9620680
符合事实的
https://maps.googleapis.com/maps/api/geocode/xml?address=component:locality=Moscow&sensor=false

<GeocodeResponse>
<status>OK</status>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Moscow, Russia</formatted_address>
<address_component>
<long_name>Moscow</long_name>
<short_name>Moscow</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>gorod Moskva</long_name>
<short_name>g. Moskva</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Moscow</long_name>
<short_name>Moscow</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Russia</long_name>
<short_name>RU</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>55.7558260</lat>
<lng>37.6173000</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>55.4899270</lat>
<lng>37.3193290</lng>
</southwest>
<northeast>
<lat>56.0096570</lat>
<lng>37.9456610</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>55.4899270</lat>
<lng>37.3193290</lng>
</southwest>
<northeast>
<lat>56.0096570</lat>
<lng>37.9456610</lng>
</northeast>
</bounds>
</geometry>
<partial_match>true</partial_match>
</result>
<result>
<type>locality</type>
<type>political</type>
<formatted_address>Moscow, ID, USA</formatted_address>
<address_component>
<long_name>Moscow</long_name>
<short_name>Moscow</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Latah</long_name>
<short_name>Latah</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Idaho</long_name>
<short_name>ID</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United States</long_name>
<short_name>US</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>46.7323875</lat>
<lng>-117.0001651</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>46.7109120</lat>
<lng>-117.0396980</lng>
</southwest>
<northeast>
<lat>46.7588820</lat>
<lng>-116.9620680</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>46.7109120</lat>
<lng>-117.0396980</lng>
</southwest>
<northeast>
<lat>46.7588820</lat>
<lng>-116.9620680</lng>
</northeast>
</bounds>
</geometry>
<partial_match>true</partial_match>
</result>
</GeocodeResponse>