0

给定当前位置、方位和距离,我正在尝试获取 GPS 坐标。

但我找不到任何与可可触感有关的东西。

我在这里找到了公式获取给定当前点、距离和方位的纬度/经度

iOS有更简单的方法吗?

提前致谢。

4

1 回答 1

1

将链接中的代码转换为 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);
}
于 2012-05-10T07:56:43.843 回答