Get the Distance Between Two Points in Latitude and Longitude

This function returns the distance between two sets of latitude and longitude points.

function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    return $miles * 60 * 1.1515;
}

Example:

PHP
$distance = getDistanceBetweenPointsNew(40.770623, -73.964367, 40.758224, -73.917404);
print "The distance is $distance";

Produces the result:
The distance is 2.6025

Copyright © Lage.us Website Development | Disclaimer | Privacy Policy | Terms of Use