1

I have implemented Google Auto suggest API in my project. I am able to restrict it within a country(India).

But the client wants to restrict it within a city(Kolkata). When I type something in input box, places should appear within Kolkata not outside.

Is there any way to restrict it within a city?

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
  • https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(inputted citie name)&language=pt_BR&key=YOUR_API_KEY use this google api to get city locations – Amitsharma Sep 05 '16 at 05:10

1 Answers1

0

From this Place Types documentation:

You may restrict results from a Place Autocomplete request to be of a certain type by passing a types parameter. The parameter specifies a type or a type collection, as listed in the supported types below. If nothing is specified, all types are returned. In general only a single type is allowed. The exception is that you can safely mix the geocode and establishment types, but note that this will have the same effect as specifying no types.

You can try the country restriction then pass a types: ['(cities)'] parameter:

Example:

function initialize() {

 var options = {
  types: ['(cities)'],
  componentRestrictions: {country: "us"}
 };

 var input = document.getElementById('searchTextField');
 var autocomplete = new google.maps.places.Autocomplete(input, options);
}

Sample request:
A request for cities containing "Vict" with results in Brazilian Portuguese:

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

Based from this answer in the related SO question, there is a feature request in public issue tracker: https://code.google.com/p/gmaps-api-issues/issues/detail?id=4433.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59