Removing the name of the state from the list of auto offers, so that the user selects a specific area / city

I use google places api to create a text field, which is an input field for the user to select his / her preferred location. I want this user to specify the exact name of the area in which he lives.

The problem is this google places api gives me: 1. Mumbai (state name) 2. Mumbai yours (city in Mumbai) 3. Mumbai Thane (city in Mumbai)

I want to delete the first option OR the entire state name, for example, Mumbai, Hyderabad, Karnataka, so that the user has only a choice to choose his region / city.

I am new to google user interfaces and sites. Please, help.

0
source share
2 answers

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 src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9CiSrNomU7HPw5PLIpFZYP6NXXOq0dlE&libraries=places&callback=initAutocomplete" async defer></script> 

I am using google sites api javascript.

+3
source

Do you use the Google Places API web service, the Google Places Javascript API library, the Google Places API for Android, or the Google Places API for iOS?

Assuming you are using a web service, you want to use the types=(cities) parameter in place autocomplete requests. For instance:

 https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Mumbai&types=(cities)&key=YOUR_API_KEY 

The (cities) and other types, such as (regions) , are described in the Google Developers Guide for Auto-Complete Locations .

0
source

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


All Articles