iPhone模拟器能够显示方向和经纬度吗?

7

我正在使用iPhone模拟器4.2版本,试图显示或记录位置服务属性,例如纬度、经度、海拔高度、水平精度、垂直精度和速度等,但它没有显示正确的参数。在方向上,实际上事件并未触发,因为其执行了CLLocation代码。

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    [self.delegate locationUpdate:newLocation];
}

未执行CLHeading代码

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    [self.delegate headingUpdate:newHeading];
}

我在这两段代码中设置了断点,但它从未触及CLHeading代码。我在init方法中更新位置和方向。

- (id) init{
if (self!=nil) {
    self.locationManager  = [[[CLLocationManager alloc] init] autorelease];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    [self.locationManager startUpdatingLocation];
    [self.locationManager startUpdatingHeading];
}
return self;
}

问题在于我不知道是由模拟器还是代码存在问题导致的?
请帮忙。

1
这是因为模拟器没有GPS跟踪功能,所以CLLocationManager无法获取您的位置信息。 - Parth Bhatt
3个回答

15

CLLocationManager 需要额外的硬件支持,因此在模拟器上无法工作。但是,您可以使用这个其他SO问题中描述的方法进行测试。

根据文档

一些位置服务需要设备上具有特定的硬件。例如,只有具有硬件指南针的设备才能提供方向信息。此类定义了几种方法,可用于确定当前可用的服务。


文档中说现在在:https://developer.apple.com/documentation/corelocation/getting_heading_and_course_information - Gabriel Goncalves

3
这个答案可以针对使用Xcode 4.2的任何人进行更新。它仍处于测试阶段,但如果你是付费开发者,你将可以访问它。此外,如果你是付费开发者,WWDC 2011有一些很好的视频,解释如何使用模拟器进行位置模拟。
请参见WWDC 2011中的“Core Location中的新内容”和“在不离开座椅的情况下测试您的位置感知应用程序”。
**注意:请再次注意,只有付费开发者才能访问这些视频。

2

看起来这种行为是默认的, 它会触发位置信息,但不会触发方向信息。

我还没有在实际硬件上测试我的应用程序来确认我的想法...

安东尼·德萨


欢迎来到Stackoverflow。别忘了阅读FAQ的所有部分。 - menjaraz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接