谷歌自动填充地点api我想设置特定状态,只有城市才能获得城市

时间:2016-10-19 11:02:19

标签: android google-maps

我想在google auto complete place api中设置特定状态。哪个州我只指定我希望得到的城市或地区的状态。即 我在州指定gujrat所以只得到gujrat的位置。可以帮助我。

  

https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyCz2s4KgGmojRTMLwIFlqmBA43_qlQDx4w&components=country:in&types=(cities)&input=dg

1 个答案:

答案 0 :(得分:1)

试试这个,

function initialize() {

     var options = {
      types: ['(cities)'],
      componentRestrictions: {country: "us"}
     };

     var input = document.getElementById('searchTextField');
     var autocomplete = new google.maps.places.Autocomplete(input, options);
    }

你可以使用bound:

var southWest = new google.maps.LatLng(sw_latitude, sw_longitude ); //South West Lat Lng
var northEast = new google.maps.LatLng(ne_latitude, ne_longitude ); //North East Lat Lng
var gujaratBounds = new google.maps.LatLngBounds( southWest, northEast );

var options = {
    bounds: gujaratBounds,
    types: ['(cities)'],
    componentRestrictions: { country: 'in' }
};

了解更多,

https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-hotelsearch

https://developers.google.com/places/web-service/autocomplete