Question

I was wondering if there's a way to obtain the accuracy of a received location from an MKMapView.

I would have thought the following code would work but it doesn't. Can I log the property directly as well?

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation {    

    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyBest) {
        NSLog(@"Best");
    }
    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyBestForNavigation) {
        NSLog(@"Best for nav");
    }
    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyHundredMeters) {
        NSLog(@"100m");
    }
    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyKilometer) {
        NSLog(@"km");
    }
    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyNearestTenMeters) {
        NSLog(@"10m");
    }
    if (userLocation.location.horizontalAccuracy == kCLLocationAccuracyThreeKilometers) {
        NSLog(@"3km");
    }    
}

A circle usually represents the accuracy of a location by wrapping it round the small blue circle so the accuracy is obviously being sent.

Thanks for any help you can offer.

Was it helpful?

Solution

The horizontalAccuracy property in CLLocation indicates how accurate the current instance of the coordinates are.

It is not the "desiredAccuracy" (the property that can be set and read in CLLocationManager) that the map view is using. As far as I know, that setting is not accessible in the MKMapView.

However, in the Breadcrumb sample app, in the BreadcrumbViewController.m file there is this comment:

// Note: we are using Core Location directly to get the user location updates.
// We could normally use MKMapView's user location update delegation but this does not work in
// the background.  Plus we want "kCLLocationAccuracyBestForNavigation" which gives us a better accuracy.

So this implies that the MKMapView is at least not using kCLLocationAccuracyBestForNavigation.

OTHER TIPS

Is this delegate method called at all? Make sure you have set showsUserLocation to YES for the MKMapView instance

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top