Question: How can you use the JQuery Auto-Completion plugin to suggest a location ("City, State"
) for an input field?
Meaning, someone wants to type in "Chicago, IL" ... so they begin typing "Chi"
and it auto-suggestions "Chicago, IL
".
My biggest hurdles is finding a service that I can query to find out all US city+state names.
I essentially want to do what the StackOverflow "Tags" input form works but form "City, State" auto completion.
There's a group called GeoNames that offers both downloadable databases and free webservices to obtain this type of data. For example, the search
http://ws.geonames.org/searchJSON?name_startsWith=Chic&country=US
will return a bunch of JSON that includes Chicago, IL (JSON properties include, among others, "name":"Chicago" and "adminCode1":"IL").
As it happens, the jQuery UI folks used this datasource for a demo of autocomplete. (Thanks NickT for the link).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With