Re: Re: Google Maps Distance Between UK Postcodes
| From: | mike | Date: | Mon, 01 Sep 2008 16:36:43 +0000 |
| Subject: | Re: Re: Google Maps Distance Between UK Postcodes | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279224@lists.php.net to get a copy of this message | ||
This is what I have:
$distance = number_format(ceil(69*rad2deg(acos(sin(deg2rad($ulat)) *
sin(deg2rad($vlat)) + cos(deg2rad($ulat)) * cos(deg2rad($vlat)) *
cos(deg2rad($ulong - $vlong))))));
where:
$ulat = latitude of user #1
$ulong = longitude of user #1
$vlat = latitude of user #2
$vlong = longitude of user #2
it seems to work properly at least with US data. I assume any
longitude/latitude date will work fine with it. If anyone has links to
other countries' zipcode mappings I'd love to be able to add that to
my site :)
(I basically took a MySQL query and mapped it to the PHP functions)
On 9/1/08, Tom Chubb <tomchubb@gmail.com> wrote:
> > <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;
> > }