Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery: How to AutoComplete "City, State"?

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.

like image 772
NickT Avatar asked Apr 06 '10 17:04

NickT


1 Answers

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).

like image 163
Jacob Mattison Avatar answered Sep 23 '22 02:09

Jacob Mattison