3
votes

I need to get new coordinates 500 meters north, south, west and east from some gps coordinates.

lat: 45.815005 long: 15.978501

it can be aproximate

Thank you

1
If you are working with a MySQL Database, then the SO Question liked above may help. If you are using PHP alone, do a search for the "Great Circle Calculator" - it will allow you to calculate Lat/Long Co-Ords based on bearing and distance, and vice-versa.Luke Stevenson
thank you,this is what i neededGale

1 Answers

4
votes

Well, without any knowledge of how to do so to start with, let's see what sort of solution I can come up with.

Finding North/South should be easy arithmetic, because the length of each line of longitude is always the same, thus distance and degrees should be linked and thus can be done by figuring the circumference of the earth around the poles in meters divided by 360 degrees to give degrees per meter. But latitudinal degrees per meter would change since the length of lines of latitude decrease the farther you are from the equator, so that would be a geometric/trigonometric function. Now, from what I know of trigonometry with spheres, cos(deg) * (pi * d) = circumference of the circle which is parallel to the plane of the equator of the sphere at degrees deg, where deg is the degrees north or south of the equator of the sphere and d is the diameter of the sphere.

So, let's see.

<?php
$lat = 45.815005; 
$long = 15.978501;
$meters = 500; //Number of meters to calculate coords for north/south/east/west

$equator_circumference = 6371000; //meters
$polar_circumference = 6356800; //meters

$m_per_deg_long = 360 / $polar_circumference;

$rad_lat = ($lat * M_PI / 180); //convert to radians, cosine takes a radian argument and not a degree argument
$m_per_deg_lat = 360 / (cos($rad_lat) * $equator_circumference);

$deg_diff_long = $meters * $m_per_deg_long;  //Number of degrees latitude as you move north/south along the line of longitude
$deg_diff_lat = $meters * $m_per_deg_lat; //Number of degrees longitude as you move east/west along the line of latitude

//changing north/south moves along longitude and alters latitudinal coordinates by $meters * meters per degree longitude, moving east/west moves along latitude and changes longitudinal coordinates in much the same way.

$coordinates['north']['lat'] = $lat + $deg_diff_long;
$coordinates['north']['long'] = $long;
$coordinates['south']['lat'] = $lat - $deg_diff_long;
$coordinates['south']['long'] = $long;

$coordinates['east']['lat'] = $lat;
$coordinates['east']['long'] = $long + $deg_diff_lat;  //Might need to swith the long equations for these two depending on whether coordinates are east or west of the prime meridian
$coordinates['west']['lat'] = $lat;
$coordinates['west']['long'] = $long - $deg_diff_lat;

?>

At least, I think that will get it. I might be totally wrong. It seems to generate coordinates with differences from the origin small enough to be only 500 meters away from it.

I also switched around to degrees per meter rather than meters per degree, but left the variable names the same.