Question

So, I need to calculate distances betweeen two points (lat-lon pairs). I've read about Haversine formula and Equirectangular approximation in Movable Type Scripts.

Since I only want to calculate short distances (less than 4 KM), is the Equirectangular formula a good approximation?

Also, I've read about lat-lon storage in MySQL databases in Google Developers documentation and they implement the Haversine formula like this:

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

My last question is, is there any big performance differences between filtering the points in the sql query (as in the example) and filtering them by code?.

Was it helpful?

Solution

When I tested haversine v equirectangular over much larger distances (1000km, within the UK), the difference was on the order of 0.1%. So for distances of 4km or less you might as well use equirectangular for speed unless you have a need for maximum accuracy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top