geolocation - SQL Distance Query without Trigonometry -
i have sqlite database, not support trig functions. sort set of lat,lng pairs in table distance compared second lat,lng pair. i'm familiar standard haversine distance formula sorting lat,lng pairs distance.
in case don't care particularly precision, points separated large distances, don't mind rounding off distances treating curves straight lines.
my question, there accepted formula kind of query? remember no trig functions!
if points within reasonable distance of each other (i.e. not across half world, , not across date line), can make correction difference between latitude , longitude (as longitude degree shorter, except @ equator), , calculate distance if earth flat.
as want sort values, don't have use square root, can add squares of differences.
example, @lat
, @lng
current position, , 2
difference correction:
select * points order (lat - @lat) * (lat - @lat) + ((lng - @lng) * 2) * ((lng - @lng) * 2)
you can calculate difference correction specific latitude 1 / cos(lat)
.
cees timmerman came formula works across date line:
pow(lat-lat2, 2) + pow(2 * min(abs(lon-lon2), 360 - abs(lon-lon2)), 2)
Comments
Post a Comment