Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparison of Lat, Long Coordinates

I have a list of more than 15 thousand latitude and longitude coordinates. Given any X,Y coordinates, what is the fastest way to find the closest coordinates on the list?

like image 435
kjloh Avatar asked Aug 30 '08 10:08

kjloh


People also ask

How do you compare lat and long?

import android. location. Location float[] distance = new float[1]; Location. distanceBetween(lat, lon, currentLat, currentLon, distance); // distance[0] is now the distance between these lat/lons in meters if (distance[0] < 2.0) { // your code... }

Which GPS coordinates are most accurate?

Together with the previous app GPS/Glonass coordinates is one of the most accurate and often chosen apps by hikers or long distance travellers who explore remote areas.


1 Answers

I did this once for a web site. I.e. find the dealer within 50 miles of your zip code. I used the great circle calculation to find the coordinates that were 50 miles north, 50 miles east, 50 miles south, and 50 miles west. That gave me a min and max lat and a min and max long. From there then I did a database query:

select *
    from dealers
    where latitude  >= minlat
      and latitude  <= maxlat
      and longitude >= minlong
      and longitude <= maxlong

Since some of those results will still be more than 50 miles away, then I used the great circle formula once more on that small list of coordinates. Then I printed out the list along with the distance from the target.

Of course, if you wanted to search for points near the international date line or the poles, than this won't work. But it works great for searches inside North America!

like image 104
Jeremy Avatar answered Oct 12 '22 12:10

Jeremy