Hi,
I have been working on a distance finding tool which gives the mileage between two UK postcodes.
I have a slight problem in that the formula I use will only work with Longitude & Latitude figures and not with the UTM system (Eastern & Northing).
The formula looks like this:
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 – $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist
$unit = strtoupper($unit);
if ($unit == “K”) {
return ($miles * 1.609344);
} else if ($unit == “N”) {
return ($miles
} else {
return $miles;
}
}
echo distance(51.75444444, -0.335277778, 51.65583333, -0.064166667, “M”) . ” Miles<br>”;
echo distance(51.75444444, -0.335277778, 51.65583333, -0.064166667, “K”) . ” Kilometers<br>”;
echo distance(51.75444444, -0.335277778, 51.65583333, -0.064166667, “N”) . ” Nautical Miles<br>”;
The Long & Lat look like the figures used above. Eastern & Northing are generally 5 figure numbers (51400 etc etc).
any ideas how i might change this formula to work with the eastern/northing figures?
Maths isn’t really my strong subject!
Thanks