5
votes

A quick question about a Lat / Long calculation.

I want to take a value set e.g. Lat: 55.123456 Long -6.123456 and work out the four points that are an arbitrary distance away.

enter image description here

As the given square, I want to work out the value for Latitude on the left and right side. Thus the red lines are 1.5km from the start point. Likewise for the longitude, the blue lines will be 1.5km from the start point. The output will be 4 points, all distances in kilometres.

In short: Latitude + Y = Latitude Value X kilometers away

Working with iPhone at the moment and its for a very rough database calculation.

EDIT: Just to clarify, the distance is so short that curvature (And hence accuracy) is not an issue.

3
You know the Earth is (more of) a sphere than a plane, right?Matt Ball
And to follow on from Matt's comment, I think the Great Circle Distance is what you're after.rickerbh
@Matt, well aware of the sphere :D The distance is so short (Sub 3km) It shouldn't matter. I merely want to add a float value to the existing point to give me a latitude or long point that is a set distance away.Colin

3 Answers

6
votes

In OBJ-C this should be a decent solution:

float r_earth = 6378 * 1000; //Work in meters for everything
float dy = 3000; //A point 3km away
float dx = 3000; //A point 3km away
float new_latitude  = latitude  + (dy / r_earth) * (180 / M_PI);
float new_longitude = longitude + (dx / r_earth) * (180 / M_PI) / cos(latitude * 180/M_PI);
3
votes

Well, for rough calculation with relatively small distances (less than 100km) you may assume that there is 40_000_000/360=111 111 meters per degree of latitude and 111 111*cos(latitude) meters per degree of longitude. This is because a meter was defined as 1/40_000_000 part of the Paris meridian;).

Otherwise you should use great circle distances, as noted in the comments. For high precision you also need to take into account that Earth is slightly oblate spheroid rather than a sphere.

1
votes
// parameter: offset in meters
float offsetM = 1500; // 1.5km

// degrees / earth circumfence
float degreesPerMeter = 360.0 / 40 000 000;
float toRad = 180 / M_PI;

float latOffsetMeters = offsetM * degreesPerMeter;
float lonOffsetMeters = offsetM * degreesPerMeter * cos (centerLatitude * toRad);

Now simply add +/- latOffsetMeters and +/- lonOffsetMeters to your centerLatitude/ centerLongitude.

Formula is usefull up to hundred kilometers.