Get the GPS coordinate given the current location, bearing and distance

微笑、不失礼 提交于 2019-12-13 05:55:24

问题


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.


回答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);
}


来源:https://stackoverflow.com/questions/10522751/get-the-gps-coordinate-given-the-current-location-bearing-and-distance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!