2017-06-01 45 views

回答

0

我想你在找Google Goocles Api。

你發送一個請求像這樣的東西: https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

再大的JSON對象回來,在那裏你可以得到lat和長

「的結果 - 幾何 - 位置 - 緯度/經度」

{ 
"results" : [ 
    { 
    "geometry" : { 
     "location" : { 
      "lat" : 37.4224764, 
      "lng" : -122.0842499 
     }, 
... 
... 

看看這裏獲取更多一些信息https://developers.google.com/maps/documentation/geocoding/intro

0

第一次加載庫:

<script type="text/javascript" 
     src="https://maps.googleapis.com/maps/api/js? 
     key=YOUR_API_KEY&libraries=places"> 
    </script> 

然後找到具體位置的細節:

<script> 
function initMap() { 
     var map = new google.maps.Map(document.getElementById('map'), { 
      center: {lat: -33.866, lng: 151.196}, 
      zoom: 15 
     }); 

     var infowindow = new google.maps.InfoWindow(); 
     var service = new google.maps.places.PlacesService(map); 

     service.getDetails({ 
      placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4' 
     }, function(place, status) { 
      if (status === google.maps.places.PlacesServiceStatus.OK) { 
      var marker = new google.maps.Marker({ 
       map: map, 
       position: place.geometry.location 
      }); 
      google.maps.event.addListener(marker, 'click', function() { 
       infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + 
       'Place ID: ' + place.place_id + '<br>' + 
       place.formatted_address + '</div>'); 
       infowindow.open(map, this); 
      }); 
      } 
     }); 
     } 

更換緯度和所需位置的經度。

更多細節請參考:

https://developers.google.com/maps/documentation/javascript/places#place_details

並且例如:

https://developers.google.com/maps/documentation/javascript/examples/place-details

相關問題