Google Geolocation API - 使用经度和纬度在文本框中获取地址? [英] Google Geolocation API - Use longitude and latitude to get address in textbox?

查看:125
本文介绍了Google Geolocation API - 使用经度和纬度在文本框中获取地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到很多关于如何根据IP地址使用Google地理定位外观获取您的位置的信息。但我想知道是否以及如何使用此服务来输入一个位置(经度和纬度)并获取当前地址或至少一个城市州。



我想在C#中做到这一点,但我会使用任何语言。



任何建议?

解决方案

您所描述的内容称为反向地理编码。 Google提供了地理编码Web服务API ,您可以从服务器端调用应用程序(使用任何语言)进行反向地理编码



例如,以下请求:


http://maps.google.com/maps/api/geocode/xml? latlng = 40.714224,-73.961452& sensor = false


...将返回如下所示的响应(截断):

 < GeocodeResponse> 
< status>确定< / status>
<结果>
< type> street_address< / type>
< formatted_address> 277 Bedford Ave,Brooklyn,NY 11211,USA< / formatted_address>
< address_component>
< long_name> 277< / long_name>
<短名称> 277< /短名称>
< type> street_number< / type>
< / address_component>
< address_component>
< long_name> Bedford Ave< / long_name>
< short_name> Bedford Ave< / short_name>
< type>路由< / type>
< / address_component>
< address_component>
< long_name>布鲁克林< / long_name>
< short_name>布鲁克林< / short_name>
< type> sublocality< / type>
< type>政治< / type>
< / address_component>
< address_component>
< long_name>纽约< / long_name>
< short_name>纽约< / short_name>
< type> locality< / type>
< type>政治< / type>
< / address_component>
< address_component>
< long_name>国王< / long_name>
<短名称>国王< /短名称>
< type> administrative_area_level_2< / type>
< type>政治< / type>
< / address_component>
< address_component>
< long_name>纽约< / long_name>
< short_name> NY< / short_name>
< type> administrative_area_level_1< / type>
< type>政治< / type>
< / address_component>
< address_component>
< long_name>美国< / long_name>
< short_name>美国< / short_name>
< type>国家< / type>
< type>政治< / type>
< / address_component>
< address_component>
< long_name> 11211< / long_name>
<短名称> 11211< /短名称>
< type> postal_code< / type>
< / address_component>
<几何>
< location>
< lat> 40.7142330< / lat>
< lng> -73.9612910< / lng>
< / location>
< location_type> ROOFTOP< / location_type>
< viewport>

< lat> 40.7110854< / lat>
< lng> -73.9644386< / lng>
< / southwest>
<东北>
< lat> 40.7173806< / lat>
< lng> -73.9581434< / lng>
< / northeast>
< / viewport>
< / geometry>
< / result>
< / GeocodeResponse>

但请注意, Google Maps API使用条款似乎禁止存储结果,除非该商店充当用于Google地图的数据缓存。您可能想与Google取得联系,并查询 Google地图API专业版为您的地理编码要求提供更灵活的使用条款。

I have noticed a lot of information about how to get your location using Google geolocation looks, based on IP address. But I am wondering if and how I could use this service to input a location (longitude and latitude) and get back the current address, or at least a city, state.

I would like to do this in C#, but I'll work with any language.

Any advice?

解决方案

What you describe is called Reverse Geocoding. Google provides a Geocoding Web Service API which you can call from your server-side application (using any language) to do reverse geocoding.

For example, the following request:

http://maps.google.com/maps/api/geocode/xml?latlng=40.714224,-73.961452&sensor=false

... will return a response that looks like the following (truncated):

<GeocodeResponse> 
 <status>OK</status> 
 <result> 
  <type>street_address</type> 
  <formatted_address>277 Bedford Ave, Brooklyn, NY 11211, USA</formatted_address> 
  <address_component> 
   <long_name>277</long_name> 
   <short_name>277</short_name> 
   <type>street_number</type> 
  </address_component> 
  <address_component> 
   <long_name>Bedford Ave</long_name> 
   <short_name>Bedford Ave</short_name> 
   <type>route</type> 
  </address_component> 
  <address_component> 
   <long_name>Brooklyn</long_name> 
   <short_name>Brooklyn</short_name> 
   <type>sublocality</type> 
   <type>political</type> 
  </address_component> 
  <address_component> 
   <long_name>New York</long_name> 
   <short_name>New York</short_name> 
   <type>locality</type> 
   <type>political</type> 
  </address_component> 
  <address_component> 
   <long_name>Kings</long_name> 
   <short_name>Kings</short_name> 
   <type>administrative_area_level_2</type> 
   <type>political</type> 
  </address_component> 
  <address_component> 
   <long_name>New York</long_name> 
   <short_name>NY</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> 
  <address_component> 
   <long_name>11211</long_name> 
   <short_name>11211</short_name> 
   <type>postal_code</type> 
  </address_component> 
  <geometry> 
   <location> 
    <lat>40.7142330</lat> 
    <lng>-73.9612910</lng> 
   </location> 
   <location_type>ROOFTOP</location_type> 
   <viewport> 
    <southwest> 
     <lat>40.7110854</lat> 
     <lng>-73.9644386</lng> 
    </southwest> 
    <northeast> 
     <lat>40.7173806</lat> 
     <lng>-73.9581434</lng> 
    </northeast> 
   </viewport> 
  </geometry> 
 </result> 
</GeocodeResponse> 

However be aware that the Google Maps API Terms of Use seem to prohibit the storage of the results, unless the store acts as a cache for data that will used in Google Maps. You may want to get in touch with Google and enquire on the Google Maps API Premier to have more flexible terms of use for your geocoding requirements.

这篇关于Google Geolocation API - 使用经度和纬度在文本框中获取地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆