Having a hard time figuring out the best way to do this…
I have a search function that takes “search terms” and “search location”. In the location input, I have an suggestion feature that brings up “city, state abbreviation” but it seems some users just do not use it(or can’t) so they end up entering just a city name… I need to append the state abbreviation after the form is submitted. I have a table with all city and state names in the U.S. but the problem is… there are multiple cities with the same name in different states… I would like to add the state abbreviation for the state that the city is most popular for(does that make sense?).
For example, if the user enters “Miami” I would like it to become “Miami, FL” as opposed to “Miami, WV”…
Any ideas?
Thanks!
You may want to consider the correlation between the “city population” and its “general popularity”.
Therefore one easy option might be to gather the population of each city, store it in the database, and if a city name is used that you need to disambiguate, you can choose the one with the largest population.
The references in the following Wikipedia article might be useful: List of US cities by population.
Google Maps resolves disambiguations in a similar manner, even though the weighting might be different:
I used to think Google Maps also takes into consideration the current viewport when resolving such issues, but searching for Miami while zoomed into the West Virginia still takes you to Florida.