基于城市名称的搜索地址google autocomplete api

时间:2016-02-20 12:50:29

标签: jquery autocomplete google-places-api

我在我的网络应用程序中使用谷歌自动完成API。我想只搜索特定城市的地址,比如选择班加罗尔作为城市名称,然后自动填充应该只显示班加罗尔的地方。以下代码仅用于搜索某个国家/地区的城市

google.maps.event.addDomListener(window, 'load', function() {

  var options = {
    types: ['(cities)'], //search only cities 
    componentRestrictions: {
      country: 'in'
    } //In the Country India only
  };
  var places = new google.maps.places.Autocomplete(document.getElementById('city'));

  google.maps.event.addListener(places, 'place_changed', function() {
    var place = places.getPlace();
    var address = place.formatted_address;
  });
});

但我想要一个这样的功能,

 google.maps.event.addDomListener(window, 'load', function() {

   var options = {
     types: ['(address)'], // search only address here
     componentRestrictions: {
       city: 'Bangalore'
     } //For Bangalore city only
   };
   var places = new google.maps.places.Autocomplete(document.getElementById('city'));

   google.maps.event.addListener(places, 'place_changed', function() {
     var place = places.getPlace();
     var address = place.formatted_address;
   });
 });

0 个答案:

没有答案