Sudarshan Kalebere
Sudarshan Kalebere

Reputation: 3929

How to restrict user to select city only from google API response

I am using google API to show autocomplete cities, but I want user to always select from available or whatever autocomplete options comes when he starts typing, if user types any city name which is not automated by google api then I have to show error. Is there any way to do this? Here I am trying so far please try editing and let me know please.

[1]: http://jsfiddle.net/uxvMF/34/

Upvotes: 2

Views: 148

Answers (1)

Dec Sander
Dec Sander

Reputation: 1447

This is probably not the simplest way but if you're selecting cities that are next to each other, you can use the bounds option for Autocomplete with strict bounds enabled

https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete

For example:

var options = {
    componentRestrictions: {
        country: 'nz'
    },
    bounds: {
        east: -1,
        west: 1,
        north: 1,
        south: -1
    },
    strictBounds: true
};

Upvotes: 1

Related Questions