How do I write a "find nearest" algorithm? e.g. a store / branch locator by address / zip / "my location"

1.8k Views Asked by At

My need is simple and commonly implemented in any location based app today, display to a user a list of all "things" in his/her area (or by a zip code / address)

Using Google Maps API (especially the new "store locator library") sounds like the safest bet, but if I would like to develop something on my own, is there a "standard" way to do so? what are the options? Yahoo geo-location API (and reverse lookup)? (Google Maps API require to use their map, not just API) purchace ZIP code files? other 3rd party services? online? offline? what is the secret?

1

There are 1 best solutions below

1
On BEST ANSWER

Hmm. Zip codes can be handled a number of ways, and it helps to get a general background on how they work: http://en.wikipedia.org/wiki/ZIP_code

I'd purchase a USPS database with GPS coordinates, and work from there. A simple SELECT SQL query, with a LIMIT or TOP 10 (or however many search results you'd like) when calculating the magnitude of the vector should work here.

It's been a while, but the algorithm for vector calculation is fairly simple, and should be easy to implemented in SQL: http://www.netcomuk.co.uk/~jenolive/vect5.html