2

how to limit the google place search boundary within a city, and establishments.

I want the user to be able to search establishments within a certain area - city

var options = {
                componentRestrictions: {
                    country: 'PH'}
            };
            var autocomplete = new google.maps.places.Autocomplete(input, options);
            autocomplete.bindTo('bounds', map);
SCS
  • 1,162
  • 3
  • 17
  • 31

1 Answers1

0

Autocomplete creates a text input field on your web page, supplies predictions of places in a UI pick list, and returns place details in response to a getPlace() request.

The (cities) type collection instructs the Places service to return results that match either locality or administrative_area3.

Use the componentRestrictions option to restrict the autocomplete search to a particular country. The following code restricts the results to cities within France.

var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};

autocomplete = new google.maps.places.Autocomplete(input, options);

For more details on how to limit searches, check this tutorial page: How to limit google autocomplete results to City and Country only

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30