how to filter address according country and city in google maps autocomplete address api

How to filter address according country and city in google maps autocomplete address api. i am able to address filter according country but i am not able to address filter according country and city. I am using following code:-

 var autocompleteFrom;
    $(document).ready(function () {
        var options = {
            types: ['geocode'],
            componentRestrictions: { country: "IL" }
        };
        var inputFrom = document.getElementById('Address');
        autocompleteFrom = new google.maps.places.Autocomplete(inputFrom, options);
        google.maps.event.addListener(autocompleteFrom, 'place_changed', fillAddrss);
    });

Upvotes: 4

Views: 3467

Answers (1)

xomena
xomena

Reputation: 32158

There is no way to apply a city filter in place autocomplete at the moment.

There is a feature request in Google issue tracker to make this happen. However we cannot see any ETA there.

I can suggest staring the feature request to add your vote and receive updates from Google.

As a workaround you can define city bounds and filter results by city bounds applying a strictBounds parameter

var options = {
    bounds: cityBounds,
    strictBounds: true,
    types: ['geocode'],
    componentRestrictions: { country: "IL" }
};

Please refer to docs for further details:

https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions

Upvotes: 4

Related Questions