Google map: calculate distance between two points(Marker)

rad = function(x) {
            return x*Math.PI/180;
         }

distanceUsingHaversine = function(sourcePoint, destinationPoint) {
     var RADIUS = 6371;    // earth's mean radius in km
    var diff_Lat  = rad(destinationPoint.lat() - sourcePoint.lat());
    var diff_Long = rad(destinationPoint.lng() - sourcePoint.lng());

    var a = Math.sin(diff_Lat/2) * Math.sin(diff_Lat/2) +
          Math.cos(rad(sourcePoint.lat())) * Math.cos(rad(destinationPoint.lat())) * Math.sin(diff_Long/2) *     Math.sin(diff_Long/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var dist =RADIUS * c;

  return dist.toFixed(3);
}

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine

Session timeout interceptor in struts 2