位置管理器的准确性不是很准确 [英] Location manager accuracy not very accurate

查看:63
本文介绍了位置管理器的准确性不是很准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将位置发送给其他用户时遇到问题。我使用Parse.com作为后端,并使用以下代码获取位置:

I am having an issue with sending location to other users. I using Parse.com as my backend and I use this code to get a location:

-(void)sendLocation{



    if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]){

        [locationManager requestWhenInUseAuthorization];

    }
    [locationManager startUpdatingLocation];



}


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    [locationManager stopUpdatingLocation]; //kill it NOW or we have duplicates

    if(!self.haveLocation) {

        self.haveLocation=YES;

        NSLog(@"didUpdateToLocation: %@", newLocation);

        self.currentLocation = newLocation;
        self.currentLocationGeoPoint= [PFGeoPoint geoPointWithLocation:self.currentLocation];

}

如果我从当前位置向自己发送消息,然后通过比较当前位置的圆和掉下的图钉,打开消息进行查看,我可以看到它们不在同一个地方,并且相距还不错。

If I send myself a message from my current location and then open the message to view it, by comparing the current location circle with the pin dropped I can see they aren't in the same place and a fair distance apart.

I具有BOOL变量haveLocation以确保仅刷新一次。我是否需要刷新几次或更长时间?任何有关如何使其更准确的指示将不胜感激!谢谢

I have the BOOL var haveLocation to make sure it is only refreshed once. Do I need to refresh it more times or something? Any pointers on how to make this more accurate would be really appreciated! Thanks

我尝试过苹果示例LocateMe:

I tried following the apple example LocateMe:

我现在有:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];

    if (locationAge > 5.0) return;

    // test that the horizontal accuracy does not indicate an invalid measurement
    if (newLocation.horizontalAccuracy < 0) return;

    // test the measurement to see if it is more accurate than the previous measurement
    if (self.bestEffortAtLocation == nil || self.bestEffortAtLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
        // store the location as the "best effort"
        self.bestEffortAtLocation = newLocation;


        if (newLocation.horizontalAccuracy <= locationManager.desiredAccuracy) {

            [locationManager stopUpdatingLocation];

            //this code after getting the location
            NSLog(@"didUpdateToLocation: %@", newLocation);
}

}

}

但是,当我点击发送位置时,它将永远运行并且不会停止更新。我也设置了 locationManager.desiredAccuracy = kCLLocationAccuracyBest;

However when I tap send location it just runs forever and doesn't stop updating.. I have locationManager.desiredAccuracy = kCLLocationAccuracyBest; set too.

推荐答案

位置管理器可能会向您发送一些更新,因为它会提高准确性。此功能旨在尽快为您提供信息,同时最终为您提供最佳信息(至少达到您要求的准确性)。您正在积极避免这些更新,因此可能会获得最不准确的信息。

The location manager may send you several updates as it improves its accuracy. This is a feature designed to give you information it as as quickly as possible, while eventually getting the best information to you (at least up to the accuracy you requested). You are actively avoiding those updates, so you are likely getting the least accurate information.

您应检查 horizo​​ntalAccuracy 以确定它是否足够精确。

You should check the horizontalAccuracy to determine if it is accurate enough for your use.

请注意,您无法将 horizo​​ntalAccuracy 与<$ c $进行比较c> kCLLocationAccuracyBest 。 最佳是常数-1。您需要将其与所需数量进行比较(以米为单位),并且可能需要设置超时时间才能放弃到达目的地的时间(系统可能无法为您提供任意准确的值)。

Note that you cannot compare horizontalAccuracy to kCLLocationAccuracyBest. "Best" is a constant -1. You need to compare it to what you need (in meters), and probably set a timeout to give up if it takes too long to get there (the system may not be able to provide you an arbitrarily accurate value.)

这篇关于位置管理器的准确性不是很准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆