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

China☆狼群 提交于 2020-01-10 05:39:05

问题


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);
    });

回答1:


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



来源:https://stackoverflow.com/questions/42810524/how-to-filter-address-according-country-and-city-in-google-maps-autocomplete-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!