I need to implement find entries with x miles of town function, so I have a town box with autosuggest attached. Currently I’m using Google’s Geocoding API to get the data for the autosuggest results, but we obviously can’t tune or alter this data and it doesn’t always come up with sensible suggestions (even with a country hint). Are there any other sources of town/city location data? I’ve tried to see if perhaps an export was available from OpenStreetMap or something but I can only find map tiles or vector map data and not POI data for town/city names and locations.
Any suggestions appreciated.
Thanks.
Geonames.org has a downloadable list of cities and even postal codes for many countries around the world along with their corresponding lat/lon point. It’s under the Creative Commons Attribution 3.0 License which means that you can use it commercially, but you have to give attribution, among other things.
While having a downloadable list may mean more work on your end in terms of implementing all of the facets of the search algorithm, the silver lining is that you don’t couple yourself to the uptime/availability of a 3rd-party web service.
The only other part that’s missing is the distance-calculation formula. You can use the greater-circle distance formula to compute distance.
I’ve done this myself a number of times. The first time you write the code, it takes a little bit to wrap your head around everything, but once you do it’s a piece of cake thereafter.
I should probably mention that I’m the founder of SmartyStreets. We do street-based address verification and not only can we tell you if an address is good or not (which helps in a significant number of ways), but we can also give you the lat/lon coordinate for a given street address which can then be plugged in to the above solution to determine proximity to nearby places.