Getting the exact location using CLLocationManager

I am starting to talk with CLLocationManager and I am trying to use the callback method below. I went outside to check it on my iPhone, and from the first few updates I seem to get gibberish, because suddenly my distance is 39 meters, although I didn’t move anywhere. Or sometimes it starts at 5, and then jump 20 meters, again without me moving somewhere. I went outside and went, and the updates from the starting point seemed “good,” and then when I returned, I returned to the starting point of 39 meters. I was wondering if I am doing the below correctly. I also included the viewDidLoad method, where I initialize my CLLocationManager object.

Is there any way to make sure my first values ​​are accurate? Thanks in advance.

- (void)viewDidLoad
{
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (startingPoint == nil) {
        NSLog(@"NIL starting point");
        self.startingPoint = newLocation;
    }

    CLLocationDistance distance = [newLocation distanceFromLocation:startingPoint];
    NSString *distanceString = [[NSString alloc] initWithFormat:@"%g m", distance];
    distanceLabel.text = distanceString;
    [distanceString release];

    numberOfUpdates++;
    NSString *countString = [[NSString alloc] initWithFormat:@"%d", numberOfUpdates];
    countLabel.text = countString;
    [countString release];
}
+3
source share
3 answers

GPS is an imperfect technology. Atmospheric conditions, satellite accessibility (and position), sky visibility, signals bouncing from nearby objects (buildings) all introduce an inherent inaccuracy into it. Although there is even a value of "accuracy" (which is usually pretty good) - even this is not completely reliable.

Aircraft cannot use GPS for accurate approaches - even their receivers are not accurate enough, and they need other technologies (which have their problems).

Try running the standard Maps application and use it to compare. I think your code is good - this is GPS jut.

, , , .

+5

, . "didUpdateToLocation" , . Apple:

NSDate* eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0)
{
   // use the value
}
+3

In your method, didUpdateyou can test the property newLocation .horizontalAccuracyfor a valid value and toss any values ​​that are impossible (or even unlikely!).

+2
source

Source: https://habr.com/ru/post/1773431/


All Articles