API to type city name and get a list of possible cities?

lisovaccaro picture lisovaccaro · Aug 8, 2012 · Viewed 63.6k times · Source

I need to know on which city my users are.

I cannot use a regular text input since there are similar named cities and users can call the same city by different names,.

I want to let users type their city and display a list of similar results, I could do it with a world cities database, jquery and sql but I'm really not dying to do it from a scratch.

Is there any api (e.g: google) that has an unique ID for each city in the world and let's you search them? Could you post a link to a similar implementation?

Answer

Andrew Leach picture Andrew Leach · Aug 8, 2012

There is the Google Places Autocomplete API, https://developers.google.com/places/documentation/autocomplete

and a library for Maps Version 3 at https://developers.google.com/maps/documentation/javascript/places#places_autocomplete

but I don't know how well it will cope with different names for the same city — although, having tried it, it does present Munich, Germany for munchen — see how well your use case performs.