Re: longitude/latitude function

From: Date: Fri, 15 Nov 2002 19:57:29 +0000
Subject: Re: longitude/latitude function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-124647@lists.php.net to get a copy of this message
That will be in KM (I'm in Canada). Just remove the "* 1.6093" to return Miles. -- Aaron Gould agould@partscanada.com Web Developer Parts Canada ----- Original Message ----- From: "Edward Peloke" <epeloke@echoman.com> To: <php-general@lists.php.net> Sent: Friday, November 15, 2002 12:22 PM Subject: RE: [PHP] longitude/latitude function > Thanks, Just curious because after looking online it seems there are several > ways to do this...many giving a slightly different answer...for example, I > went to mapquest and put in two cities and the mileage was 1500, the > function returned 1700. Also, the function says it prints in miles and kms > but it only seems to print one of them...do you know which one? I guess I > should look at the freshmeat site before I bother you with any other > questions. > > Thanks again!!! > Eddie > > -----Original Message----- > From: Aaron Gould [mailto:webdevel@partscanada.com] > Sent: Friday, November 15, 2002 11:50 AM > To: Edward Peloke; php-general@lists.php.net > Subject: Re: [PHP] longitude/latitude function > > > I got that from „ > ²çÆH9‹T;’!http://freshmeat.net/projects/zipdy/?topic_id=66. It's a > program called Zipdy that does these calculations. There's also a similar > function on the US government census site (can't remember where though), but > I liked Zipdy's better. > > -- > Aaron Gould > agould@partscanada.com > Web Developer > Parts Canada > > > ----- Original Message ----- > From: "Edward Peloke" <epeloke@echoman.com> > To: <php-general@lists.php.net> > Sent: Friday, November 15, 2002 11:55 AM > Subject: RE: [PHP] longitude/latitude function > > > > Thanks Aaron, > > > > If you don't mind me asking, where did you get it? It seems to give a > > better answer than my function. > > > > Thanks! > > Eddie > > > > -----Original Message----- > > From: Aaron Gould [mailto:webdevel@partscanada.com] > > Sent: Friday, November 15, 2002 11:04 AM > > To: Edward Peloke; php-general@lists.php.net > > Subject: Re: [PHP] longitude/latitude function > > > > > > Try this snippet... I can't vouch for its accuracy since I am not a > > mathematician: > > > > <? > > // Function takes latitude and longitude of two places as input > > // and prints the distance in miles and kms. > > function calculateDistance($lat1, $lon1, $lat2, $lon2) > > // Convert all the degrees to radians > > $lat1 = deg2rad($lat1); > > $lon1 = deg2rad($lon1); > > $lat2 = deg2rad($lat2); > > $lon2 = deg2rad($lon2); > > > > // Find the deltas > > $delta_lat = $lat2 - $lat1; > > $delta_lon = $lon2 - $lon1; > > > > // Find the Great Circle distance > > $temp = pow(sin($delta_lat / 2.0), 2) + cos($lat1) * cos($lat2) * > > pow(sin($delta_lon / 2.0), 2); > > > > $EARTH_RADIUS = 3956; > > > > $distance = ($EARTH_RADIUS * 2 * atan2(sqrt($temp), sqrt(1 - $temp)) * > > 1.6093); > > > > return $distance; > > } > > ?> > > > > > > -- > > Aaron Gould > > agould@partscanada.com > > Web Developer > > Parts Canada > > > > > > ----- Original Message ----- > > From: "Edward Peloke" <epeloke@echoman.com> > > To: <php-general@lists.php.net> > > Sent: Friday, November 15, 2002 11:20 AM > > Subject: [PHP] longitude/latitude function > > > > > > > Has anyone ever written a php function to take the longitude and > latitude > > of > > > two destinations and calculate the distance? > > > > > > I am working on one but the output is just a little off. > > > > > > Thanks, > > > Eddie > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#124647) next »