Re: Google Maps Distance Between UK Postcodes

From: Date: Thu, 11 Sep 2008 15:17:07 +0000
Subject: Re: Google Maps Distance Between UK Postcodes
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-279894@lists.php.net to get a copy of this message
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

« previous php.general (#279894) next »