核心定位精度问题

发布于 2024-07-27 15:09:19 字数 481 浏览 12 评论 0原文

我有一个位置管理器设置如下的程序:

self.locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

我需要十米以内的精度,但是,需要调用几次 didUpdateToLocation 委托方法才能找到该精度的位置。 我将如何延迟对该方法的调用,或者只是指示何时达到所需的精度以便继续执行程序。

现在它尝试继续返回第一个位置。 即使是第二次位置更新也没有预期的那么准确。

提前致谢!

I have a program with a location manager set up like this:

self.locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; 
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

I need the accuracy to within ten meters, however, it takes a few calls of the didUpdateToLocation delegate method to find the location at that accuracy. How would I go about delaying the call of this method or just indicate when the desired accuracy is achieved in order to proceed with the program.

Right now it tries proceeds with the first location returned. Even the second location update is not as accurate as expected.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娜些时光,永不杰束 2024-08-03 15:09:19

由于每个委托调用都包含一个准确度数字,因此只需从该方法返回,直到达到您所需的准确度(警告:这可能永远不会发生)。

您不能简单地跳转到十米结果 - 这就是为什么它被称为“期望”精度而不是强制精度是有原因的。 您必须给它时间来计算更准确的位置。

Since each delegate call includes an accuracy figure, simply return from the method until your desired accuracy is reached (warning: that may never happen).

You can't simply jump to a ten meter result - there's a reason why it's called "desired" accuracy and not mandatory accuracy. You have to give it time to calculate more exact positions.

终止放荡 2024-08-03 15:09:19

我最近解决了这个问题,并最终通过巧妙地阅读文档发现 CoreLocation 在单独的线程中运行,因此您可以启动它,然后在更新时检索事件。 它位于标题 “获取用户的位置”。 因此,这里是您开始更新的地方:

- (void)startStandardUpdates
{
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = none;
    [locationManager startUpdatingLocation];
}

如果您将委托设置为“self”,它将向定义 start 方法的同一类发送事件,因此您只需添加以下内容即可检索事件:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation
{
    if (newLocation.horizontalAccuracy < 30.0)
    {
        NSLog(@"latitude %+.6f, longitude %+.6f\n",
                newLocation.coordinate.latitude,
                newLocation.coordinate.longitude);
        [manager stopUpdatingLocation];
    }
}

这样它将保留接收事件,然后关闭 GPS 接收器以节省能源。 当然,如果超时,它需要一个超时以及某种方法来存储和接受具有最佳水平精度的位置,但我还没有弄清楚如何做到这一点。

I've recently tackled this problem and discovered, by cleverly reading the documentation at long last, that CoreLocation runs in a separate thread, so you can start it up and then retrieve events as it updates. It's in the documentation under the rubric "Getting the User's Location". So here's where you start updating:

- (void)startStandardUpdates
{
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.distanceFilter = none;
    [locationManager startUpdatingLocation];
}

If you make the delegate "self", it will send events to the same class where the start method is defined, so then you just have to add the following to retrieve the events:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation
{
    if (newLocation.horizontalAccuracy < 30.0)
    {
        NSLog(@"latitude %+.6f, longitude %+.6f\n",
                newLocation.coordinate.latitude,
                newLocation.coordinate.longitude);
        [manager stopUpdatingLocation];
    }
}

This way it will keep receiving events and then turn off the GPS receiver to save energy. Of course it needs a time out and some way to store and accept the location with the best horizontal accuracy if it times out, but I haven't figured out how to do that yet.

转身以后 2024-08-03 15:09:19

一种策略是启动计时器足够长的时间以获得修复(用户也可以接受)

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

启动位置管理器提供更新。 当计时器到期(或者您获得可接受的精度)时,停止更新并使用该位置。

这可能是你能得到的最好的。 如果位置仍然不够准确,您可能希望为用户提供重试位置的选项。

One strategy is to start a timer for a period long enough to get a fix (which will also be acceptable to the user)

+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

Start the location manager delivering updates. When the timer expires (or you get an acceptable accuracy) stop the updates and use that location.

It's probably the best you are going to get. You may want to give the user the option to try again for a location if it is still not accurate enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文