2012-04-04 33 views

Trả lời

28

có. Chỉ cần sử dụng Google Geocoding và API địa điểm https://developers.google.com/maps/documentation/geocoding/https://developers.google.com/maps/documentation/places/

Ví dụ (có nguồn gốc từ here):

var geocoder; 

function initialize() { 
    geocoder = new google.maps.Geocoder(); 
} 

function codeLatLng(lat, lng) { 
    var latlng = new google.maps.LatLng(lat, lng); 
    geocoder.geocode({ 
    'latLng': latlng 
    }, function (results, status) { 
    if (status === google.maps.GeocoderStatus.OK) { 
     if (results[1]) { 
     console.log(results[1]); 
     } else { 
     alert('No results found'); 
     } 
    } else { 
     alert('Geocoder failed due to: ' + status); 
    } 
    }); 
} 

google.maps.event.addDomListener(window, 'load', initialize); 
+0

bạn có thể cung cấp một ví dụ? – Jackson

+2

https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse – rijndael

+1

Nên sử dụng kết quả [0] cho kết quả đầu tiên chứ không phải kết quả [1]. – IceWarrior353

10

Có thể truy cập thông tin này gửi một yêu cầu GET đơn giản để các thiết bị đầu cuối geocode.

ví dụ: đánh https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=API_KEY sẽ tạo ra các phản ứng sau:

{ 
    "results" : [ 
     { 
     "address_components" : [ 
      { 
       "long_name" : "277", 
       "short_name" : "277", 
       "types" : [ "street_number" ] 
      }, 
      { 
       "long_name" : "Bedford Avenue", 
       "short_name" : "Bedford Ave", 
       "types" : [ "route" ] 
      }, 
      { 
       "long_name" : "Williamsburg", 
       "short_name" : "Williamsburg", 
       "types" : [ "neighborhood", "political" ] 
      }, 
      { 
       "long_name" : "Brooklyn", 
       "short_name" : "Brooklyn", 
       "types" : [ "sublocality", "political" ] 
      }, 
      { 
       "long_name" : "Kings", 
       "short_name" : "Kings", 
       "types" : [ "administrative_area_level_2", "political" ] 
      }, 
      { 
       "long_name" : "New York", 
       "short_name" : "NY", 
       "types" : [ "administrative_area_level_1", "political" ] 
      }, 
      { 
       "long_name" : "United States", 
       "short_name" : "US", 
       "types" : [ "country", "political" ] 
      }, 
      { 
       "long_name" : "11211", 
       "short_name" : "11211", 
       "types" : [ "postal_code" ] 
      } 
     ], 
     "formatted_address" : "277 Bedford Avenue, Brooklyn, NY 11211, USA", 
     "geometry" : { 
      "location" : { 
       "lat" : 40.714232, 
       "lng" : -73.9612889 
      }, 
      "location_type" : "ROOFTOP", 
      "viewport" : { 
       "northeast" : { 
        "lat" : 40.7155809802915, 
        "lng" : -73.9599399197085 
       }, 
       "southwest" : { 
        "lat" : 40.7128830197085, 
        "lng" : -73.96263788029151 
       } 
      } 
     }, 
     "place_id" : "ChIJd8BlQ2BZwokRAFUEcm_qrcA", 
     "types" : [ "street_address" ] 
     }, 

    ... Additional results[] ... 

https://developers.google.com/maps/documentation/geocoding/intro#reverse-example

Các vấn đề liên quan