Zend - The PHP Company




Algorithms

Add Code


Lat_Long_2_Miles  

Type: code fragment
Added by: farrukh
Entered: 04/12/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 6592
Computes the shortest distance between 2 points (locations) on the earth surface given the Latitude/Longitude.


<?php

function calcMiles($lat1$lon1$lat2$lon2) { 

$deg2mile 69.09;  //for earth
$temp1 cos(deg2rad($lat1));
$temp2 cos(deg2rad($lat2));

$dist sqrt$temp1 $temp2 pow($lon1 $lon2 2) + pow($lat1 $lat22) );
$miles $dist $deg2mile
$miles sprintf("%0.2f",$miles); 
return 
$miles
}
?> 


Usage Example




Rate This Script





Search



This Category All Categories