Deepak Shinde Deepak Shinde - 5 days ago 7
Javascript Question

place autocomplete for selected city

I have a drop-down menu for selecting city and an autocomplete text-box. I want only locations form selected city in drop-down.

function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('auto')),{
bounds: new google.maps.Circle({
center: new google.maps.LatLng( 18.520430,73.856744 ),
radius: 500
}).getBounds(),
types: ['establishment']
});

autocomplete.addListener('place_changed', function(){});
}


I use above code for place auto complete but I want to dynamically pass lag. and lat. to this function. How can I do that? please help me.
I'd like to hve functionality like swiggy.com .

Answer

When new city is selected and you have new lat,lng of that city, use this piece of code to update the bound of autocomplete widget with new value of lat and lng:

var bounds = new google.maps.LatLngBounds();
var latLng = new google.maps.LatLng(lat, lng);
bounds.extend(latLng);
autocomplete.setBounds(bounds);
Comments