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?
Close up longitude/latitude calculations
Moderator: General Moderators
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;
}- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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;- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
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.