How to limit Google places api autocomplete for some city names and all state names?

<form> <input id="pac-input" value="" class="controls" type="text" placeholder="Search Box"> <input type="button" id="find" value="find" /> </form> <script> function initAutocomplete() { var options = { componentRestrictions: { country: "IN" } }; // Create the search box and link it to the UI element. var input = document.getElementById('pac-input'); var searchBox = new google.maps.places.Autocomplete(input, options); } </script> <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9CiSrNomU7HPw5PLIpFZYP6NXXOq0dlE&libraries=places&callback=initAutocomplete" async defer></script> 

I want the search text, such as "Maharashtra, India", "Mumbai", "India" not to have. In principle, I only need regions and settlements, and not the names of states or the names of cities. Can anyone help?

+5
source share
1 answer

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

If you look at the sample code in the "JavaScript + HTML" section, the API allows you to set filters, for example, settings. So, just set the types according to your criteria, and you should be good to go.

Cheers, Mrugesh

0
source

Source: https://habr.com/ru/post/1236543/


All Articles