5
<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 that in searchbox text like "Maharashtra,india", "mumbai", "india" should not come.Basically I need only regions and localities and not state names or city names to appear in suggestion. Can anybody help ?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Piyush Sahu
  • 802
  • 7
  • 10
  • Do you mean (1) that you want the same set of places suggested, but the way those places are displayed to be different (e.g. to suppress the country name), or (2) a different set of suggestions (e.g. to suppress suggestions for states and countries)? If (2) take a look at http://stackoverflow.com/a/33862858/806600 which is very similar. If (1) please give a specific example of what you get vs. what you'd like to get to help explain. – spiv Nov 23 '15 at 02:32
  • Suppose I type "mum" I am getting results in autosuggest as : "Mumbai,Maharashtra,India" "Mumbai Airport,Mumbai,Maharashtra,India" "Mumbai Central,Mumbai,Maharashtra,India" "Mumbai Central Tulsiwadi,Mumbai,Maharashtra,India" Mumbra,Thane,Maharashtra I don't want result like "Mumbai,Mahrashtra,India" to come in autosuggest.Similarly the state names like : "Maharashtra India","Uttar Pradesh India" – Piyush Sahu Nov 23 '15 at 04:45
  • Ok, that helps a little, but I'm still not sure what you're asking. You've listed results that you *don't* want. What are some results you *do* want for an input of "mum"? – spiv Nov 23 '15 at 05:01
  • I want that first result i.e. "Mumbai,Maharashtra,India" should not appear and except that all other 4 results should come – Piyush Sahu Nov 23 '15 at 05:13

2 Answers2

0

Please refer : 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, establishments. So, just set the types to your criteria and you should be good to go.

Cheers, Mrugesh

  • Can you post a exact working sample code as you have in the question above to [codepen.io](http://codepen.io) ? I can have a look at it, if you do so. – Mrugesh Mohapatra Nov 26 '15 at 07:30
0

How to limit google autocomplete results to City and Country only

You can refer this answer.

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

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