CLLocationManager 不适用于非无线连接?
我有一个 Mac 应用程序,想要使用核心位置,但是,当我没有使用 wifi 但使用以太网电缆连接时,核心位置 (CLLocationManager) 报告操作无法完成。
确切的错误消息是
The operation couldn't be completed. (kCLErrorDomain error 0.)
如果我始终连接到同一路由器(即 wifi 或以太网电缆),为什么 CLLocationManager 仅适用于 wifi 而不适用于以太网连接?
任何建议将不胜感激。
谢谢。
编辑:
这是一些代码。
我将位置管理器定义为实例变量,然后像这样
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:ICMinimumUpdateDistance];
监视位置管理器的委托方法,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// Filter out points before the last update
NSTimeInterval timeSinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:dateOfLastUpdate];
if (timeSinceLastUpdate > 0)
{
//Do stuff
}
}
我还使用委托方法检查错误
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location Error:%@", [error localizedDescription]);
}
在上面的代码中,位置管理器使用无效的 newLocation (错误的时间戳)进行更新,并且然后位置管理器调用委托错误方法。
I have a Mac app and would like to use core location, however, when I am not on wifi but connected using an ethernet cable, core location (CLLocationManager) reports that the operation could not be completed.
The exact error message is
The operation couldn't be completed. (kCLErrorDomain error 0.)
If I am always connected to the same router (ie. either wifi or ethernet cable) why does CLLocationManager only work for wifi and not for the ethernet connection?
Any suggestions would greatly be appreciated.
Thanks.
Edit:
Here is some code.
I define my location manager as an instance variable like so
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:ICMinimumUpdateDistance];
I then monitor the location manager's delegate method like so,
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// Filter out points before the last update
NSTimeInterval timeSinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:dateOfLastUpdate];
if (timeSinceLastUpdate > 0)
{
//Do stuff
}
}
I also check for errors using the delegate method
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"Location Error:%@", [error localizedDescription]);
}
In the code above, the location manager updates with an invalid newLocation (bad time stamp) and then the location manager calls the delegate error method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于笔记本电脑中缺少 GPS,OSX 上的核心定位使用 (skyhook) 服务或类似服务。
该服务维护一个 WIFI 接入点及其位置的数据库(可能由启用了 GPS 和 WiFi 的 iPhone 进行更新)并进行查询。
因此,通过提供您可以看到的接入点列表以及它们的相对信号强度,系统能够大致对您所在的位置进行三角测量。
因此,您需要启用 wifi,并且需要有效的互联网链接(但互联网不需要通过 wifi,您可以让机场不关联)
For lack of a GPS in your laptop, core-location on OSX uses the (skyhook) service, or something similar.
The service maintains a database of WIFI access-points and their positions (possibly updated by iPhones that do have GPS and wifi enabled) which is queried.
So by feeding a list of access points you can see, and their relative signal strengths the system is able to triangulate roughly where you are.
So you need both wifi enabled, and a working internet link (but internet shouldn't need to be over wifi, you can leave the airport un-associated)
我也注意到了这一点。如果您打开“日期和时间”的“时区”选项卡,通过以太网连接到互联网时,系统偏好设置中的时间窗格显示要连接到无线网络以确定您当前的位置。这让我相信 CoreLocation 事实上确实需要无线连接。
I've noticed this too. If you open the Time Zone tab of the Date & Time pane in System Preferences while connected to the internet via ethernet, it says to connect to a wireless network to determine your current location. This leads me to believe that CoreLocation does, in fact, require a wireless connection.