Colin
Colin

Reputation: 735

Latitude / Longitude Distance Calculation

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.

Upvotes: 5

Views: 2719

Answers (3)

Colin
Colin

Reputation: 735

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);

Upvotes: 6

AlexWien
AlexWien

Reputation: 28767

// 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.

Upvotes: 1

begemotv2718
begemotv2718

Reputation: 868

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.

Upvotes: 3

Related Questions