0

I'm trying to get a GPS coordinate given the current location, bearing and distance.

But I can't find any related to cocoa-touch.

I've found the formula here Get lat/long given current point, distance and bearing

Is there an easier method for iOS?

Thanks in advance.

Community
  • 1
  • 1
AReality
  • 69
  • 1
  • 11
  • There's no built-in method. Try [this Objective-C implementation](http://stackoverflow.com/questions/6633850/calculate-new-coordinate-x-meters-and-y-degree-away-from-one-coordinate) of the formula you link to. –  May 09 '12 at 20:58

1 Answers1

1

Converted the code in the link to Objective-C.

- (double)degreesToRadians:(double)degrees {
    return degrees * M_PI / 180;
}

- (double)radiansToDegrees:(double)radians {
    return radians * 180/ M_PI;
}


- (CLLocationCoordinate2D)remoteCoordinate:(CLLocationCoordinate2D)localCoordinate withDistance:(double)distance withBearing:(double)bearing {

    double earthRadius = 6378.1;         // Radius of Earth in kilometres.

    double rLat1 = [self degreesToRadians:localCoordinate.latitude];     // Convert latitude to radians
    double rLon1 = [self degreesToRadians:localCoordinate.longitude];    // Convert longitude to radians

    double rLat2 = asinl( sinl(rLat1) * cosl(distance / earthRadius) + cosl(rLat1) * sinl(distance / earthRadius) * cosl(bearing) );
    double rLon2 = rLon1 + atan2l( sinl(bearing) * sinl(distance/earthRadius) * cosl(rLat1), cosl(distance/earthRadius) - sinl(rLat1) * sinl(rLat2) );

    double dLat2 = [self radiansToDegrees:rLat2];        // Convert latitude to degrees
    double dLon2 = [self radiansToDegrees:rLon2];        // Convert longuitude to degrees

    return CLLocationCoordinate2DMake(dLat2, dLon2);
}
AReality
  • 69
  • 1
  • 11