I am trying to calculate the displacement between two coordinates in meters, Is there a function in here
maps that does this calculation?
If not, how do I effectively calculate distance between the two coordinate points in JavaScript.
I am trying to calculate the displacement between two coordinates in meters, Is there a function in here
maps that does this calculation?
If not, how do I effectively calculate distance between the two coordinate points in JavaScript.
I think you are looking for the distance() method in the nokia.maps.geo.Coordinate
class. An example of usage can be found in the Find Nearest Marker example on the HERE Maps Community pages on GitHub.
I found this php function (based on Vincenty's algorithm), and it works great in calculating displacement between 2 coordinates,
<?php
function vincentyGreatCircleDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000){
// convert from degrees to radians
$latFrom = deg2rad($latitudeFrom);
$lonFrom = deg2rad($longitudeFrom);
$latTo = deg2rad($latitudeTo);
$lonTo = deg2rad($longitudeTo);
$lonDelta = $lonTo - $lonFrom;
$a = pow(cos($latTo) * sin($lonDelta), 2) +
pow(cos($latFrom) * sin($latTo) - sin($latFrom) * cos($latTo) * cos($lonDelta), 2);
$b = sin($latFrom) * sin($latTo) + cos($latFrom) * cos($latTo) * cos($lonDelta);
$angle = atan2(sqrt($a), $b);
return $angle * $earthRadius;
}
?>
Call:
<?php $distance_in_meters = vincentyGreatCircleDistance(53.6235,-1.34307, 51.6554, -2.3445 ); ?>