Iphone 使用指南针指向实际坐标位置,而不是仅仅指向北方
我已经看到了一些这样的例子,但不确定具体如何实现它,(例如)在(void)startup中是否需要调用calcBearingWithLatitude 我所要做的就是让指南针从记忆中提取一个点,并用这个点作为它的“北”,可以这样说,并指向它,不需要距离之类的东西 到现在为止,我的实现文件如下所示Iphone 使用指南针指向实际坐标位置,而不是仅仅指向北方,iphone,compass-geolocation,direction,heading,bearing,Iphone,Compass Geolocation,Direction,Heading,Bearing,我已经看到了一些这样的例子,但不确定具体如何实现它,(例如)在(void)startup中是否需要调用calcBearingWithLatitude 我所要做的就是让指南针从记忆中提取一个点,并用这个点作为它的“北”,可以这样说,并指向它,不需要距离之类的东西 到现在为止,我的实现文件如下所示 @implementation TrackerViewController @synthesize locationManager; @synthesize compass; @synthesize
@implementation TrackerViewController
@synthesize locationManager;
@synthesize compass;
@synthesize headingLabel;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([CLLocationManager headingAvailable]) {
} else {
[[[[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device doesn't support heading updates"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease] show];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
double heading = [newHeading magneticHeading] * M_PI / 180.0;
self.compass.transform = CGAffineTransformMakeRotation(-heading);
self.headingLabel.text = [NSString stringWithFormat:@"%d°", (int)[newHeading magneticHeading]];
NSLog(@"%d", (int)[newHeading magneticHeading]);
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
// NSLog(@"Error!");
if (error.code == kCLErrorDenied) {
[[[[UIAlertView alloc] initWithTitle:@"Error"
message:@"User didn't allow heading updates"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease] show];
[self.locationManager stopUpdatingHeading];
}
}
- (void)viewDidLoad {
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate=self;
//Start the compass updates.
[locationManager startUpdatingHeading];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)dealloc {
self.locationManager = nil;
self.compass = nil;
self.headingLabel = nil;
[super dealloc];
}
@end
我会找到坐标A到坐标B之间的方位角,然后使用该方位角作为罗盘方位角从坐标A到坐标B的偏移量 这里有两个用于查找坐标方向的链接
如果希望指南针方位在移动时更新,使其始终指向坐标B,则可能需要在获得新方位或位置时重新计算 你能为指南针创建一个自定义航向吗?