2

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.

user1168056
  • 401
  • 8
  • 19
  • I applied the same logic but used verticalAccuracy when the horizontalAccuracy was not returning a valid result. What I found was that: Accuracy Key: -1.000000 = BEST, -2.000000 = NAV, 10.000000 = 10m, 100.000000 = 100m, 1000.000000 = 1km, 3000.000000 = 3km and the result obtained from the map (using simulator) was: -1 – csb Feb 06 '13 at 04:47

2 Answers2

1

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.

  • Yes, i've set the desired accuracy to BestForNavigation but obviously this accuracy is not guaranteed. So i would need to obtain the user's location through CLLocationManager to get the accuracy of the user's current location? Seems a little pointless to me. (more memory, power). – user1168056 Feb 14 '12 at 14:21
0

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

basvk
  • 4,437
  • 3
  • 29
  • 49