位置管理器的准确性不是很准确

Location manager accuracy not very accurate

我在向其他用户发送位置时遇到问题。我使用 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 haveLocation 来确保它只刷新一次。我需要刷新它更多次吗?任何关于如何使它更准确的指示将不胜感激!谢谢

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

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

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

请注意,您不能将 horizontalAccuracykCLLocationAccuracyBest 进行比较。 "Best" 是常数-1。您需要将它与您需要的(以米为单位)进行比较,并且可能设置超时以在到达那里花费太长时间时放弃(系统可能无法为您提供任意准确的值。)