如何使用google api for web从address_components获取地点ID?

时间:2016-02-11 13:22:07

标签: javascript google-maps-api-3

如何使用google api for web从address_components获取地点ID?是否有可能获得标题的ID?

1 个答案:

答案 0 :(得分:0)

$(document).ready(function() {
    $(document).on('change', '#s', function () { 
       window.setTimeout(function () {
       googleMapsLoaded(); }, 300); 
    }); 
}); 

var autocomplete; function initialize() { 
var options = { 
   types : ['(regions)'] }; 
   var input = document.getElementById('s'); 
   autocomplete = new google.maps.places.Autocomplete(input , options, googleMapsLoaded); 
} 

var map = google.maps.event.addDomListener(window, 'load', initialize);         

function googleMapsLoaded(){
   var place = autocomplete.getPlace(); 
   console.log(place.place_id); 
}