iPhone模拟器3.2(iPad)中的核心定位

6

所以,我正在尝试将我的应用移植到iPad上。我正在使用CoreLocation。

苹果表示iPad确实具有

Location:
Wi-Fi
Digital compass
Assisted GPS (Wi-Fi + 3G model)
Cellular (Wi-Fi + 3G model)

因此,应该可以获取我的iPad(至少带有3G模型)的位置,大约为3公里半径就足够了。

但在模拟器中(3.2 iPad),它不起作用(在模拟器中运行3.1.3会模拟出库比蒂诺)。

有没有办法在模拟器中(3.2 iPad)获取位置? 我住在德国,在这里iPad还没有发布,所以我无法在我的设备上测试它。

谢谢!

编辑

这就是我尝试获取连接的方式

locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
locationManager.delegate = self;
[locationManager startUpdatingLocation];

在3.2版本中,locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error总是会被调用,在3.1.3版本中则不会。

error对象的格式如下:

Error Domain=kCLErrorDomain Code=0 "Operation could not be completed. (kCLErrorDomain error 0.)"

编辑

所以我处理它的方式大致是这样的:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

    #ifdef TARGET_IPHONE_SIMULATOR
    // Cupertino
    CLLocation *simulatorLocation = [[CLLocation alloc] initWithLatitude:37.33168900 longitude:-122.03073100];
    [self locationManager:locationManager didUpdateToLocation:simulatorLocation fromLocation:nil];
    [simulatorLocation release];
    #else
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ErrorNotification"  object:NSLocalizedString(@"GPS-coordinates could not be detected",@"")];
    #endif

}

虽然很混乱,但它确实有效。

编辑2:尝试启用您的机场,这也可能解决问题!

3个回答

5

那么iPad模拟器默认不会给我位置吗? - choise
使用您提供的链接处理了它。请参阅我的问题帖子以了解我如何处理它。 - choise
2
@选择: 今天我才发现,当您的Mac关闭了机场(Wi-Fi)时,模拟器不会提供位置信息。至少在XCode 3.2.3中是这样的情况。 - progrmr
哎呀,我的机场已经禁用了,是的。谢谢!我会试一试的。 - choise
@progrmr,感谢你找到了这个问题,我一直在苦苦寻找为什么除了我以外的所有人都能得到Cupertino位置。但这并不环保:现在我必须打开我的机场卡并消耗电力,尽管我不用它做其他任何事情(我使用网络卡进行互联网访问)。 - Elise van Looij
很高兴能够帮助到您,或许您可以给这个答案点个赞? - progrmr

0

那不是我的问题。在3.2上,模拟器中的CoreLocation无法工作。没有“库珀蒂诺模拟”。我编辑了我的问题。 - choise

0

你可能还想查看我的FTLocationSimulator

它可以读取由Google Earth生成的KML文件,提供连续的位置更新。它还会在MKMapView中使用模拟位置更新来更新蓝色的用户位置点。


是的,我想我在最新的 Macoun 上看到了这个 ;) - choise
你参加了我的演讲?太好了,我感到非常荣幸! :) - Ortwin Gentz

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