Google Geolocation API - Use longitude and latitude to get address in textbox?

后端 未结 8 625
有刺的猬
有刺的猬 2021-01-31 05:25

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 t

8条回答
  •  臣服心动
    2021-01-31 05:50

    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):

     
     OK 
      
      street_address 
      277 Bedford Ave, Brooklyn, NY 11211, USA 
       
       277 
       277 
       street_number 
       
       
       Bedford Ave 
       Bedford Ave 
       route 
       
       
       Brooklyn 
       Brooklyn 
       sublocality 
       political 
       
       
       New York 
       New York 
       locality 
       political 
       
       
       Kings 
       Kings 
       administrative_area_level_2 
       political 
       
       
       New York 
       NY 
       administrative_area_level_1 
       political 
       
       
       United States 
       US 
       country 
       political 
       
       
       11211 
       11211 
       postal_code 
       
       
        
        40.7142330 
        -73.9612910 
        
       ROOFTOP 
        
         
         40.7110854 
         -73.9644386 
         
         
         40.7173806 
         -73.9581434 
         
        
       
      
     
    

    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.

提交回复
热议问题