开发者

How do I implement auto-complete for City / State fields on a form?

I want to implement City and State auto suggest in a form textbox. How do I do this?

Weather.com has a great example on this on their front page.

Questions:

  1. Where can I find a complete USA listing of city and state pairings? And is there an open API for this?
  2. Do any existi开发者_Python百科ng scripts/frameworks exists that already perform this auto-suggest task of city+state for textboxes?


If you're looking for a nice database of world cities with population > 1000, check out the geonames.org database. They have a sql dump available. Among other things, you'll also get countries, regions, and latitude/longitude from this database.

In general, the search term that might be helpful to you if you're getting your feet wet is GIS (geographic information systems).


try http://plugins.jquery.com/project/jq-autocomplete

http://en.wikipedia.org/wiki/List_of_United_States_cities_by_population or, how about this one? http://www.census.gov/popest/cities/SUB-EST2008-4.html

this is the oficial page of U.S. Census Bureau. You can parse the CSV.

Besides, you don't neeed AJAX if you have already the info in an array... but you have to fill it first.

You might wanna see this too

http://forums.asp.net/t/1373395.aspx


Rather than maintaining your own database, I'd suggest you check out the Freebase Suggest plugin for jQuery. See this similar question.

That plugin will do all the auto-completion and even the suggestion UI for you (you just point it to a text box) and you can specify that you just want to auto-complete locations (or only US counties, or whatever). It might be a little US-centric, but it sounds like that will work for your particular use case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜