位置管理员的准确性不太准确

时间:2015-05-06 13:27:50

标签: ios cllocationmanager

我遇到向其他用户发送位置的问题。我使用Parse.com作为我的后端,并使用此代码获取位置:

-(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];

}

如果我从当前位置向自己发送消息,然后打开消息进行查看,通过将当前位置圈与丢弃的针脚进行比较,我可以看到它们不在同一个地方且距离相当远

我有BOOL var hasLocation以确保它只刷新一次。我需要刷新次数或更多次吗?任何有关如何使其更准确的指示将非常感谢!感谢

我尝试了苹果示例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;

1 个答案:

答案 0 :(得分:2)

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

您应该检查horizontalAccuracy以确定它是否足够准确供您使用。

请注意,您无法将horizontalAccuracykCLLocationAccuracyBest进行比较。 “最佳”是常数-1。你需要将它与你需要的东西(以米为单位)进行比较,并且如果到达那里需要太长时间(系统可能无法为你提供任意准确的值),可能会设置超时以放弃。(