RE: [PHP] lat lon function
| From: | (Edward Peloke) | Date: | Tue, 08 Apr 2003 18:26:32 +0000 |
| Subject: | RE: [PHP] lat lon function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-142939@lists.php.net to get a copy of this message | ||
Thanks for all the help, I am using this mysql query that I got from someone
of the mysql list (thanks Jason)
$query="SELECT zipcode FROM zipData WHERE
(POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\
"2\"))<($radius*$radius)
where radius is the number of miles in my search circle and $lon and $lat is
the longitude and latitude from the main airport.
Thanks,
Eddie
-----Original Message-----
From: Don Read [mailto:dread@texas.net]
Sent: Tuesday, April 08, 2003 2:16 PM
To: Edward Peloke
Cc: Php-General@Lists. Php. Net
Subject: RE: [PHP] lat lon function
On 08-Apr-2003 Edward Peloke wrote:
>
> Don,
>
> How would I get distance? If my search is for a place with a lat of 30
> and
> long of 87 and I see a place with a lat of 31 and long of 88, how do you
> get
> the rough distance?
>
Forgot Pythagoras ?
c^2 = a^2 + b^2
mysql> set @a:=31-30;
Query OK, 0 rows affected (0.00 sec)
mysql> set @b:=88-87;
Query OK, 0 rows affected (0.00 sec)
mysql> set @d:=SQRT(POW(@a,2) + POW(@b,2));
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @d * 69;
+-----------------+
| @d * 69 |
+-----------------+
| 97.580735803744 |
+-----------------+
1 row in set (0.00 sec)
97.6 miles assuming a flat earth. To get a true distance, google 'spherical
trig' or 'law of cosines'.
Regards,
--
Don Read dread@texas.net
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.