在我的应用程序中,我有一个经度为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);
}
Run Code Online (Sandbox Code Playgroud)
但上面的代码总是将箭头旋转到约.每个位置北2-3度.
我的问题类似于这个Stack Overflow问题.但是使用此链接中的代码我的方向错误.请帮帮我.
如果任何使用加速度计或gyrodata的想法对我有帮助.
提前.
iphone xcode objective-c cllocationmanager compass-geolocation
我正在开发一个指南针,可以从我当前的位置指向对象的其他位置.目前我正在关注此链接:使用指南针指向位置
我觉得指向我当前位置与对象之间是不正确的.任何人都可以帮我如何开发指南针,可以从我当前的位置指向对象的其他位置?