【问题标题】:iPhone Compass ProgrammingiPhone 指南针编程
【发布时间】:2010-01-12 11:22:46
【问题描述】:

我正在为 iphone 3GS 开发一个指南针应用程序。我已经使用 CoreLocation 框架 我用过的指南针方法……

 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

...获取标题的方法。

我的问题是如何在不移动 iphone 的情况下获得“315° NW,90° E,140° SE”之类的值。 我没有 3GS iphone 所以,如果有人有什么想法,请帮忙。

谢谢。

【问题讨论】:

  • 我不确定我是否明白你在问什么。你能澄清一下你的问题吗?如果您询问如何从 CLHeading 对象中提取罗盘航向,请查看其 trueHeading 或 MagneticHeading 属性。
  • 不,当用户按下开始按钮时,我有一个指向直线的箭头,然后指南针事件开始,箭头将移动到一个固定点,例如 315° NW、90° E、140° SE 等。那么我应该如何检测上面给出的坐标。谢谢。
  • 当你收到 -locationManager:didUpdateHeading: 消息时,看一下磁头属性;如果是 90°,那就是东方,调整你的箭头等。你是在问如何绘制箭头?
  • 为您没有也无法测试的设备开发应用程序不是一个好主意。如果你是为 iPhone 3G S 构建这个,你需要去买一个。

标签: iphone compass-geolocation


【解决方案1】:

我在需要我的假航向和位置数据的类的 @implementation 之前使用这个 sn-p。

#if (TARGET_IPHONE_SIMULATOR)
@interface MyHeading : CLHeading
    -(CLLocationDirection) magneticHeading;
    -(CLLocationDirection) trueHeading;
@end

@implementation MyHeading
    -(CLLocationDirection) magneticHeading { return 90; }
    -(CLLocationDirection) trueHeading { return 91; }
@end

@implementation CLLocationManager (TemporaryLocationFix)
- (void)locationFix {
    CLLocation *location = [[CLLocation alloc] initWithLatitude:55.932 longitude:12.321];
    [[self delegate] locationManager:self didUpdateToLocation:location fromLocation:nil];

    id heading  = [[MyHeading alloc] init];
    [[self delegate] locationManager:self didUpdateHeading: heading];
}

-(void)startUpdatingHeading {
    [self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}

- (void)startUpdatingLocation {
    [self performSelector:@selector(locationFix) withObject:nil afterDelay:0.1];
}
@end
#endif

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多