Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Calculate Distance Jump to:  
Category: >> PHP Code >> Calculate Distance Bookmark and Share

<< lastnext >>

Snippet Name: Calculate Distance

Description: Calculates the distance between two pairs of latitude longitude coordinates. Returns the distance in miles or kilometers.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: February 26th, 2009

<?PHP
 
FUNCTION distance($lat1, $lng1, $lat2, $lng2, $miles = TRUE)
{
     $pi80 = M_PI / 180;
     $lat1 *= $pi80;
     $lng1 *= $pi80;
     $lat2 *= $pi80;
     $lng2 *= $pi80;
 
     $r = 6372.797; // mean radius of Earth in km
     $dlat = $lat2 - $lat1;
     $dlng = $lng2 - $lng1;
     $a = SIN($dlat / 2) * SIN($dlat / 2) + COS($lat1) * COS($lat2) * SIN($dlng / 2) * SIN($dlng / 2);
     $c = 2 * ATAN2(SQRT($a), SQRT(1 - $a));
     $km = $r * $c;
 
     RETURN ($miles ? ($km * 0.621371192) : $km);
}
 
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 73 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?