Calculate Distance From Latitude And Longitude

Add Tool

Calculate Distance From Latitude And Longitude


Calculate Distance From Latitude And Longitude

Here is a code snippet which allows you to calculate distance from latitude and longitude in either miles, kilometers or nautical miles.

<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) { 

$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) 
       * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
 
      if ($unit == "K") {
          return ($miles * 1.609344);
      } else if ($unit == "N") {
          return ($miles * 0.8684);
      } else {
          return $miles;
     }
}
?>

I think this small php snippets is enough to Calculate Distance From Latitude And Longitude


Tags: calculate distance from latitude and longitude, calculate latitude and longitude from distance and bearing, latitude and longitude, longitude and latitude, latitude and longitude finder
Payza

About Masum Billah

Calculate Distance From Latitude And Longitude Hi I am Md. Masum Billah Contributor of this website. I always like to share various things with other. In this website I am sharing web design related tips and tricks, necessary web development tools, source codes for beginner and advance web developer.


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: Calculate Distance From Latitude And Longitude


adf.ly