0

I have a CLLocationCoordinate2D (c1) and a CLLocation (l1), so I have lat/long values for each point and I can calculate the distance in meters between them using:

[c1 distanceFromLocation:l1]

How can I find the coordinates of a point (c2) 100 meters closer to l1 than c1 (along the same bearing)?

enter image description here

I have calculated it using basic trig using the following:

  1. used the difference in latitude and longitude to calculate the hypotenuse and angle
  2. used the ratio between the distance to cl and the distance to c2 to get the hypotenuse of a triangle ending at c2
  3. used cos and sin to calculate the longitude and latitude of c2

But this seems like a hacky way of doing it as it doesn't take into account of curvature and seems to be using latitude and longitude in a way they are not supposed to be used. It does seem to work over short distances though.

Undistraction
  • 42,754
  • 56
  • 195
  • 331
  • How accurate are you trying to be? 100m plus or minus a few inches, or 100m plus or minus a few yards? – eric.mitchell Nov 18 '11 at 12:00
  • Certainly not inches. It needs to be accurate to a few meters over distances between 10 meters and 10 miles. – Undistraction Nov 18 '11 at 12:11
  • 1
    It seems to me that the way you are doing it is correct; I don't believe there is any native method of CLLocation to accomplish what you want. What is wrong with the way you are doing it? – eric.mitchell Nov 18 '11 at 12:21
  • It seems kind of crude to me. It's a lot of calculation to do (I need to do it for multiple coordinates intensively) and it involves treating latitude and longitude as if they were cartesian coordinates. – Undistraction Nov 18 '11 at 12:25
  • The only other way I would do it (but is really the same process) is calculate the x- and y-offset of c1 and c3, then calculate the ratio between c1 to c2 and c1 to c3. In this example that would be .33333; then just multiply that ratio with your two offsets, and then add them to your original c1 coordinate. – eric.mitchell Nov 18 '11 at 12:26
  • 1
    Also see: http://stackoverflow.com/questions/6633850/calculate-new-coordinate-x-meters-and-y-degree-away-from-one-coordinate –  Nov 18 '11 at 15:04

2 Answers2

1

After a bit of research, I found a basic formula for calculating curved distance between two points on the earth's surface:

dlon = lon2 - lon1 
dlat = lat2 - lat1 
a = { sin(dlat/2) }^2 + [ cos(lat1) * cos(lat2) * { sin(dlon/2) }^2 ] 
c = 2 * arcsin(min(1,sqrt(a))) 
d = R * c
eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
1

Although Rickay's answer was helpful, I eventually used the following excellent library which has many useful functions for Core Location calculations: https://github.com/100grams/CoreLocationUtils

Undistraction
  • 42,754
  • 56
  • 195
  • 331