How to automatically fill out a form field with a city and state?

I have a free form text field that allows the user to enter a city and state, for example. "Chicago, Illinois."

What I would like to do is when the user starts typing to start displaying suggestions for completed city + state combinations (just like Stackoverflow automatically sets the "tags" field below when you create a question).

Question : Is there an API that returns every combination of USA cities and states? Or can I load every city + state that exists in the USA somewhere?

+3
source share
3 answers

Yes, there are a number of solutions for the same task, you can try this . You will also need to load the mysql database in the USA , and then change the table names or script for the autocomplete class to work successfully.

Here is another beautiful option.

http://www.nodstrum.com/2007/09/19/autocompleter/

+2
source

Not sure about any existing APIs to do this for you, but here are some tools to help you get started:

5 /, , .

+1

http://geonames.org has an API for finding each city, landmark, mountain, etc. I use it myself. Regarding automatic completion, the other answers are good resources.

0
source

Source: https://habr.com/ru/post/1731692/


All Articles