Re: Google Maps Distance Between UK Postcodes

From: Date: Mon, 01 Sep 2008 14:56:08 +0000
Subject: Re: Google Maps Distance Between UK Postcodes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-279220@lists.php.net to get a copy of this message
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/]

« previous php.general (#279220) next »