在我的应用程序中,我有1个固定位置的经度 - 纬度。现在,使用iPhone设备的用户可以在任何地方移动,甚至他可以旋转他的设备,箭头(某些uiimageview)应该指向该修复位置,以便用户每次都可以获取指向该位置的路线。我尝试如下。如何将方向箭头旋转到特定位置
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocationCoordinate2D here = newLocation.coordinate;
[self calculateUserAngle:here];
}
-(void) calculateUserAngle:(CLLocationCoordinate2D)user {
NSLog(@"my destination is %f ; %f", fixlocLat, fixlocLon);
degrees = degrees + atan2(sin(fixlocLon-user.longitude)*cos(fixlocLat),cos(user.latitude)*sin(fixlocLat) - sin(user.latitude)*cos(fixlocLat)*cos(fixlocLon-user.longitude));
//get angle between user location and fix location
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
arrow.transform = CGAffineTransformMakeRotation((degrees-newHeading.trueHeading) * M_PI/180);
}
,但上面的代码将永远旋转箭头约。每个位置向北2-3度。
我的问题与this Stack Overflow question类似,但使用此链接中的代码我得到错误的方向。 请帮助我。
以及使用加速度计或gyrodata的任何想法对我都有帮助。
thanx提前。
位置有多远?如果距离很远,则可能需要[大圆距离](http://en.wikipedia.org/wiki/Great-circle_distance)计算。 – RabinDev
我们如何使用xcode(物镜c)中的大圆距离计算和距离可以远远大约。千公里。 – Dhawal
距离是可变的,它会随着用户移动而更新,但范围大约在0到1000km之间。 – Dhawal