Rui*_*pes 0 iphone distance cllocation cllocationdistance
我正在完成一个应用程序希望我需要向用户显示他和大约500坐标之间的距离.
使用CLLocation方法计算它,效果很好,但在iPhone 4中大约需要1分钟才能完成每个位置的计算.
最好的方法是什么?用span?还有其他更快的方法吗
谢谢大家,
瑞
我认为Sahgal是对的,这里有一些代码,也许它会帮助你.
+(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords andDestination:(CLLocationCoordinate2D)secondCoords
{
// this radius is in KM => if miles are needed it is calculated during setter of Place.distance
double nRadius = 6371;
// Get the difference between our two points
// then convert the difference into radians
double nDLat = (firstCoords.latitude - secondCoords.latitude)* (M_PI/180);
double nDLon = (firstCoords.longitude - secondCoords.longitude)* (M_PI/180);
double nLat1 = secondCoords.latitude * (M_PI/180);
double nLat2 = secondCoords.latitude * (M_PI/180);
double nA = pow ( sin(nDLat/2), 2 ) + cos(nLat1) * cos(nLat2) * pow ( sin(nDLon/2), 2 );
double nC = 2 * atan2( sqrt(nA), sqrt( 1 - nA ));
double nD = nRadius * nC;
NSLog(@"Distance is %f",nD);
return nD; // converts to miles or not (if en_) => implicit in method
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3103 次 |
| 最近记录: |