All calculations give, and methods - approximations, but within the tolerances for what you need.
The circumference of the earth is about 40,076,000 meters.
the distance traveled per degree of latitude is always the same and is simply part of the earth’s circle.
the distance in degrees in longitude varies depending on your latitude (this ring on glode gets closer to the poles).
therefore, for a given distance m, the corresponding latitude and longitude
earthcirc = 40076000; // at Lat and Lon for distance m (in meters) LatDelta = (m * 360) / earthcirc; LonDelta = (m * 360) / abs(eathcirc*cos(lat));
This gives you wide deltas of long latitude for easy retrieval of your data. but on the fingers of the candidate, you have to do a full distance calculation, since the angle of the square is quite a bit more than 5 km.
distance between 2 lat / long
distLat = (lat1-lat2) * earthcirc) / 360; distLong = (long1-long2) * earthcirc * cos((lat1+lat2)/2) / 360; dist = sqrt( sqr(distLat) + sqr(distLong) );
I know that most compilers / languages use radians for cos / sin functions, but its simplicity is explained in degrees.
since the search for your data is the easiest way to order either lat or long, then you can perform a binary search to find a possible place to check instead of a full scan. There are better ways to organize the data (ATVs), but for 2500 ish records I would not worry
source share