CLLocationManager 未通过 Wifi 更新位置
我们有一个完全依赖于持续位置更新的应用程序,并且发现当手机没有获取 gps 时,即使设备连接到 wifi 网络,也不会调用 didUpdateToLocation。为了进一步进行此测试,我在第四代 iPod Touch 上加载了该应用程序,得到了相同的结果。
需要澄清的是,当 GPS 可用时,该应用程序可以在 iPhone 4 上完美运行。直到客户在他的办公室用 iPhone 4 进行测试时我们才注意到这个问题,他知道他没有 GPS。
我认为位置管理器应该支持 wifi 作为确定位置的方法,但事实似乎并非如此。
这是我的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (locationManager==nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
NSLog(@"Accuracy best: %f distance filter none: %f", kCLLocationAccuracyBestForNavigation, kCLLocationAccuracyNearestTenMeters);
}
[locationManager startUpdatingLocation];
...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{....
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{....
据我所知,您无需做任何特殊的事情即可使 locationManager 通过 wifi 工作 - 但现在我发现它根本不起作用。
顺便说一句,我的手机设备是运行 iOS 5 beta 7 的 iPhone 4 和 iPod touch iOS 4.1。
We have an app that is totally dependent on constant location updates and found that when the phone isn't getting gps, didUpdateToLocation isn't being called even if the device is connected to a wifi network. To further this test, I loaded the app on a 4th gen iPod Touch with the same results.
To clarify, the app workings perfectly on the iPhone 4 when GPS is available. We didn't notice the problem until the client tested it on his iPhone 4 in his office where he knows he doesn't get gps.
I thought that location manager was supposed to support wifi as a method to determine location, but this doesn't appear to be the case.
Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (locationManager==nil) {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
NSLog(@"Accuracy best: %f distance filter none: %f", kCLLocationAccuracyBestForNavigation, kCLLocationAccuracyNearestTenMeters);
}
[locationManager startUpdatingLocation];
...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{....
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{....
As far as I thought, there isn't anything special that you have to do to make locationManager work over wifi - and now I find out it doesn't work at all.
BTW- My phone device is an iPhone 4 running iOS 5 beta 7 and an ipod touch iOS 4.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现应用程序首次打开时 didUpdateLocation 被调用...一次。这让我觉得当你只处理 wifi 时,位置管理器就在
仅限 startMonitoringSignificantLocationChanges 模式。
I have discovered that didUpdateLocation is being called... once, when the app first opens. It makes me think that when you're dealing with wifi only, location manager is in
startMonitoringSignificantLocationChanges mode only.
尝试调用:
您可能还需要在 self.locationManager 上配置位置管理器参数。
Try calling:
Possible you may need to configure your location manager parameters on self.locationManager as well.
听起来好像您的 Wi-Fi 接入点未知。为了确保这不是编码错误,请在模拟器中启动 Safari 并查看它是否找到您的位置。如果没有,问题出在您的未知 Wi-Fi AP 上。解决方案是让外界知道您的 AP。为此,请访问 http://www.skyhookwireless.com 并阅读说明。此站点使您能够更新 XPS 系统中的 Wi-Fi 接入点信息。注意:我花了六个星期才连接上,但现在可以了。
It sounds as if your Wi-Fi Access Point is unknown. To make sure that it is not a coding error, in the simulator start Safari and see whether it finds your location. If it doesn't, the problem is your unknown Wi-Fi AP. The solution is to make your AP known to the outside wold. In order to do that, go to http://www.skyhookwireless.com and read the instructions. This site enables you to update your Wi-Fi Access Point information in the XPS system. Note: it took six weeks before I was hooked up, but it works now.