Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 799
Colin Avatar asked Mar 24 '13 21:03

Colin


1 Answers

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);
like image 77
Colin Avatar answered Sep 20 '22 23:09

Colin