6

I have a mapView with annotationViews and the userLocation blue dot.

I am using the following code to get the blue dot:

[self.mapView setShowsUserLocation:YES];

The annotationViews are selectable and have callouts.

However if an annotationView is close to the user's location sometimes the blue dot steals the touch.

I can set an annotationView.enabled = NO; and it will show the annotationView but it will not steal a touch from a close by annotationView.

I would like to set the user location blue dot annotationView to enabled=NO, so it does not steal the touch of close by annotationViews.

I can set the title of the blue dot with:

self.mapView.userLocation.title = @"title here..."

But I cannot disable the blue dot.

Thanks!

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
user1607483
  • 143
  • 5
  • 1
    You can't do self.mapView.userLocation.enabled = NO? – Nathan Villaescusa Oct 08 '12 at 22:59
  • If you don't mind making your own annotation view, you can override the view that gets used in `-mapView:viewForAnnotation:`. A lot of work though! – tc. Oct 08 '12 at 23:28
  • @Nathan Villaescusa, I though the same thing. Unfortunately trying 'self.mapView.userLocation.enabled = NO' results in an error: Property 'enabled' not found on object of type 'MKUserLocation' – user1607483 Jan 17 '13 at 19:36
  • @0xSina Unfortunately I want the annotation, the blue dot to be visible, just not selectable. Setting the 'annotation.hidden = YES' for the userLocation results in the entire annotation not being visible. Thanks! – user1607483 Jan 17 '13 at 19:39
  • @tc Overriding the annotation with a custom annotation is an option. However, I have not found a way to recreate the blue circle location accuracy pulse around the built in blue dot annotation. But this would be the fall back solution. Thanks! – user1607483 Jan 17 '13 at 19:42

1 Answers1

8

You can set enabled on the user location's MKAnnotationView by getting a reference to it in the didAddAnnotationViews delegate method (so you can be sure the view is ready):

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *ulv = [mapView viewForAnnotation:mapView.userLocation];
    ulv.enabled = NO;
}

(There is no enabled property on the userLocation model object -- it's a property of the view.)