I tried to calculate the distance between two points in Google map.
Some of the link i found they are usingdistanceTo()
and somewhere it is calculated using distanceBetween()
.
Which is best to calculate distance?
This link might be helpful to you.
it allows to calculate the distance between two latitude longitude points:
This script calculates great-circle distances between the two points (i.e)the shortest distance over the earth’s surface using the ‘Haversine’ formula.
var R = 6371; // Radius of the earth in km
var dLat = (lat2-lat1).toRad(); // Javascript functions in radians
var dLon = (lon2-lon1).toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With