Page 1 of 1
Close up longitude/latitude calculations
Posted: Sun Sep 24, 2006 7:52 pm
by Todd_Z
I am writing a script that has four input variables:
longitude & latitude
delta X and delta Y [both in meters]
I have a function that will evaluate the new longitude and latitude if the distances were miles, but in this case, I am dealing with meter distances of approximately 100 meters, and I feel like the error bounds are two great using the formula designed for miles. Has anyone written a function that deals with this? Or is there a simple conversion from degrees long to meters and degrees lat to meters?
Posted: Sun Sep 24, 2006 9:24 pm
by feyd
Do you have the formula for miles handy (with units)? Conversion to meters isn't too far from it, so it's likely a few constants changes and you're gold.
Posted: Sun Sep 24, 2006 9:32 pm
by Todd_Z
Code: Select all
function distance ( $lat1, $lon1, $lat2, $lon2 ) {
$theta = $lon1 - $lon2;
$dist = sin( deg2rad($lat1) ) * sin( deg2rad($lat2) ) + cos( deg2rad($lat1) ) * cos( deg2rad($lat2) ) * cos( deg2rad($theta) );
$dist = acos( $dist );
$dist = rad2deg( $dist );
$miles = $dist * 60 * 1.1515;
return $miles;
}
Posted: Sun Sep 24, 2006 9:41 pm
by feyd
Since there are no units where it matters, I can only suggest the slightly dirty approach:
Code: Select all
$meters = bcmul( bcmul($dist, '69.09', 20), '1609.344' /* meters per mile */, 20);
return $meters;
Posted: Sun Sep 24, 2006 10:38 pm
by Todd_Z
Dirty isn't an option, this has to be as error-less as I can possibly get.
Posted: Sun Sep 24, 2006 10:40 pm
by feyd
That's as close as I can get you without knowing the exact units for the literals.
Posted: Mon Sep 25, 2006 5:07 am
by panic!
I was trying to do something like this when I was using the google maps API, I didn't ever find a way to find the EXACT calculation if you do, please post it up.

Posted: Mon Sep 25, 2006 6:13 am
by CoderGoblin
Nearest I can think of is to use the Great Circle distance in kilometers and then the meters to avoid milage conversion. This doesn't take into account the elavation distance. The main trouble you have is that the earth is not round. I know there are quite a few specalist GEO forums out there and I would recommend you check if there is one local to the area you are concerned with. Also note that the information on Long/Lat can also be out depending on the model it uses (WGS84,ED50,NAD,TD) compared with the location you need.