Mehul Tank
Mehul Tank

Reputation: 195

Google autocomplete place api i want to set specific state that sate get only city

i want to set specific state in google auto complete place api. which state i specify only that state of city or area i want to get in response. i.e i specify gujrat in state so get only location of gujrat only . can help me out.

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

Upvotes: 1

Views: 2227

Answers (1)

Mr. J
Mr. J

Reputation: 320

Try this,

function initialize() {

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

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

you can use 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' }
};

for more,

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

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

Upvotes: 2

Related Questions