US State and their Respectives City

Hello all!

I need to a implement a sign-up form with US states and city selector. Is there already a helper os something that implements or makes it easier to implement this for Rails.Also when i select the state all the city appears for that state in the other select list.

Btw, where could I get a list of US states and US cities? Is there any webservice for that ? Or just copy and paste from somewhere else?

Thanks in advance,

Salil Gaikwad

See if this helps !

Dave

Don't do that - the select that you generate is going to be far too large to be practical. It's hard to get a clear count of exactly how many cities are involved, but the best estimate I've seen places it somewhere around 20,000. An autocompleter might help, but you'll still have the issue that city data can get stale (new ones are incorporated frequently). You'd be better served using a geocoder to verify that addresses actually match an existing DB (Google Maps, etc) and inquiring with the user if the address doesn't match. Take a look at the GeoKit gem.

--Matt Jones

FYI, to add some metrics here, I have a list of cities-in-states that I sourced from somewhere (US Census site, probably), and that list has 55,324 entries. So loading this into a select box, even dynamically, seems problematic. As the previous poster suggested, use AJAX-based autocomplete to keep the list of the server side instead.

- D

FYI, to add some metrics here, I have a list of cities-in-states that I sourced from somewhere (US Census site, probably), and that list has 55,324 entries.

I got my data from here. U.S. 5 Digit ZIP Code Database - Updated Nov 1, 2023 The standard version has 29,778 non duplicate cities.

So loading this into a select box, even dynamically, seems problematic. As the previous poster suggested, use AJAX-based autocomplete to keep the list of the server side instead.

+1.

I got my data from here. U.S. 5 Digit ZIP Code Database - Updated Nov 1, 2023 The standard version has 29,778 non duplicate cities.

Some ZIP codes cover multiple cities- i.e., 02573 is Martha's Vineyard, Tisbury, and Vineyard Haven. So I think we're talking apples and oranges here.

- D