[PHP] Re: Google Maps Distance Between UK Postcodes



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
.



Relevant Pages

  • Re: Elevation Calculator for Distant Object?
    ... >>ground distance from the observer to a point directly below the object. ... >>That is, as an example, suppose that I know I'm 400 miles from Los ... >>see a more general calculation. ... > earth, you could simplify this calculation enough that you might not ...
    (sci.astro.amateur)
  • The Inner Earth. Part 5 of 5.
    ... Subject: The Inner Earth. ... the inside of the earth's crust, ... pole is exactly one-half the distance through the earth's crust. ... Thus, if the earth's crust is three hundred miles in thickness, ...
    (sci.skeptic)
  • The Inner Earth. Part 5 of 5.
    ... Subject: The Inner Earth. ... the inside of the earth's crust, ... pole is exactly one-half the distance through the earth's crust. ... Thus, if the earth's crust is three hundred miles in thickness, ...
    (talk.religion.newage)
  • Re: Why the sun is hot
    ... The distance from the Earth to the Sun is about 94 million miles. ... The Sun circles the Earth once every 24 hours in a roughly circular orbit. ...
    (sci.astro.amateur)
  • Re: GPS navigation
    ... to a satellite of several thousand miles and the curvature of the earth ...
    (rec.aviation.piloting)