I am working on a website which requires distance calculation between two zip-codes. I have a database table which consists of zip-codes and their related latitudes and longitudes. I make use of this to calculate distance between the two places.
But I have a problem that this gives me straight line distance and not driving distance - how can I find that?
I'm using the following code
$lat1 = $this->deg_to_rad($lat1);
$lon1 = $this->deg_to_rad($lon1);
$lat2 = $this->deg_to_rad($lat2);
$lon2 = $this->deg_to_rad($lon2);
$delta_lat = $lat2 - $lat1;
$delta_lon = $lon2 - $lon1;
$temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2);
$distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp));