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);
}

Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI