views:

67

answers:

1

I have a database of places with lat/lng and I have incoming requests with lat/lng. I'd like to find the closest lat/lng in the database to the incoming request. Is there any existing library or algorithm for doing this? Searching online keeps pointing me to Google's reverse geocoding library which isn't quite what I had in mind.

As always, any help is absurdly appreciated. :)

+1  A: 

You dont really need an online service for this. Just apply the correct mathematical formula. See here for some examples (in JavaScript etc)...

http://www.movable-type.co.uk/scripts/latlong.html

Another alternative formula is here...

http://wiki.answers.com/Q/What_is_the_formula_for_distance_using_latitude_and_longitude

barrylloyd
he is looking for off-line solutions (see the title--which I changed for clarity).
Muad'Dib
@Muad'Dib: The title was edited, it originally said 'Non-online'. So that is why I suggested you dont need an online service to do this. The Haversine formula on the first page I linked to, can be used to calculate the distance between a pair of lat/lng points. Just take that formula and put it into your application or database.
barrylloyd
@barrylloyd yes, I am the one who edited the title. He is searching, according to the title, for a non-online solution. which would suggest that he already knows he can do it off-line :)
Muad'Dib
@Muad'Dib: Ok, I'm still slightly confused, but many apologies if I have misunderstood the question.
barrylloyd
@barrylloyd Not trying to be an ass, just wanted to make sure everyone was on the same page.
Muad'Dib
@Muad'Dib: No problem, I wasn't offended :)
barrylloyd

related questions