At 5:37 PM +0100 9/1/08, Colin Guthrie wrote:
Tom Chubb wrote:
That's all way above my head, but I think I'll be able to understand it
after a strong coffee!
I should point out that this is really just trig and is only an
approximate distance as the crow flies. Not even sure if it takes
the curvature of the earth into consideration, but it's probably
"good enough" for most things.
I've reviewed your code and it does not include the curvature of the
earth -- it's a flat surface computation.
Considering that my other profession is Geophysicist, I'm kind of up
on those sort of things. The Earth is an oblate spheroid and the
computation to include the curvature of the earth would be a bit more
involved.
But, I agree that your computation should be "good enough" for most things.
Cheers,
tedd
Here's yet another "get distance" thing from lat/long, but it's for miles.
function getDistance($lat1, $lon1, $lat2, $lon2)
{
$rad = doubleval(pi()/180.0);
$lon1 = doubleval($lon1) * $rad;
$lat1 = doubleval($lat1) * $rad;
$lon2 = doubleval($lon2) * $rad;
$lat2 = doubleval($lat2) * $rad;
$theta = $lon2 - $lon1;
$distance = acos(sin($lat1) * sin($lat2) + cos($lat1) *
cos($lat2) * cos($theta));
if ($distance < 0)
{
$distance += pi();
}
$distance = $distance * 6371.2;
$miles = doubleval($distance * 0.621);
$distance = sprintf("%.2f", $distance);
$miles = sprintf("%.4f", $miles);
return $miles;
}
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php