根据当前位置,方位和距离获取GPS坐标 [英] Get the GPS coordinate given the current location, bearing and distance
本文介绍了根据当前位置,方位和距离获取GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图根据当前的位置,方位和距离得到一个GPS坐标。
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
有没有更容易的iOS方法?
Is there an easier method for iOS?
在此先感谢。
推荐答案
将链接中的代码转换为Objective-C。
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);
}
这篇关于根据当前位置,方位和距离获取GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文