views:

337

answers:

4

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.

A: 

You either need to make an ajax call to the server whenever a key is pressed to update the "auto complete" drop down, or include an array of all the possible "city-state" strings and filter them when a key is pressed.

Jeremy
A: 

You can download a free CSV that contains cities and states at: http://www.maxmind.com/app/geolitecity

You will have to create your own database, but with this information, you will be able to query the info you need.

superUntitled
+5  A: 

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

JacobM
Very cool! Thanks, @JacobM :)
macek
Very Cool, I found then the official integration at the link below --> http://jqueryui.com/demos/autocomplete/#remote-jsonp
NickT
A: 

Based on user information above, I was able to locate the following JQuery Geoname integration demo

http://jqueryui.com/demos/autocomplete/#remote-jsonp

NickT