[PHP] Re: Google Maps Distance Between UK Postcodes
- From: tedd.sperling@xxxxxxxxx (tedd)
- Date: Thu, 11 Sep 2008 11:17:07 -0400
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
.
- Follow-Ups:
- RE: [PHP] Re: Google Maps Distance Between UK Postcodes
- From: "Boyd, Todd M."
- RE: [PHP] Re: Google Maps Distance Between UK Postcodes
- References:
- Re: [PHP] Re: Google Maps Distance Between UK Postcodes
- From: "Tom Chubb"
- Re: Google Maps Distance Between UK Postcodes
- From: Colin Guthrie
- Re: [PHP] Re: Google Maps Distance Between UK Postcodes
- Prev by Date: Mysqli issue
- Next by Date: Re: [PHP] Securing pages & sections
- Previous by thread: Re: Google Maps Distance Between UK Postcodes
- Next by thread: RE: [PHP] Re: Google Maps Distance Between UK Postcodes
- Index(es):
Relevant Pages
|