Re: Google Maps Distance Between UK Postcodes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tom Chubb wrote:
I thought it would be easy but it seems that I need to convert each postcode
to Lat/Long using Geocoding and then work it out from there.

That's the best way: then just do something like:

Here's how I do it in SQL, but the principle is the same in PHP, so I'm sure you'll be able to convert it.

HTHs

Col

<snip>
public static function Distance($latA, $lngA, $latB, $lngB, $blnMiles = false)
  {
    $multiplier = 6371;
    if ($blnMiles)
      $multiplier *= 1.609344;

    $rv = <<<ESQL
  (ACOS(
    SIN(RADIANS($latA)) * SIN(RADIANS($latB))
+ COS(RADIANS($latA)) * COS(RADIANS($latB)) * COS(RADIANS($lngB) - RADIANS($lngA)))
  * $multiplier)
ESQL;
    return $rv;
  }
</snip>




--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux