The blue location point is selected, falsely intercepting strokes from my MKAnnotationViews

I have a normal map in my iOS application, where the option "Show users location" is enabled - this means that I have my usual blue dot on the map showing my location information and accuracy. Callout is disabled in code.

But I also have custom MKAnnotationViews that are built around the map, all of which have custom callouts.

This works fine, but the problem is that when my location is on the MKAnnotationView location, the blue dot (MKUserLocation) intercepts the touch, so MKAnnotationView is not affected.

How to disable user interaction with a blue dot so that strokes are intercepted by MKAnnotationViews, rather than a blue dot?

This is what I am doing so far:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation;
{
    if (annotation == self.mapView.userLocation)
    {
        [self.mapView viewForAnnotation:annotation].canShowCallout = NO;
        return [self.mapView viewForAnnotation:annotation];
    } else {
        ...
    }
}
+3
source share
1 answer

Turning off the leader does not disable viewing touches ( didSelectAnnotationViewit will still be called up).

To disable user interaction in the annotation view, set its property enabledto NO.

However, instead of setting enabledin NOin the delegate method viewForAnnotation, I suggest doing this in the delegate method didAddAnnotationViewsinstead and in viewForAnnotation, just return nilfor MKUserLocation,

Example:

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation;
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        return nil;
    }

    //create annotation view for your annotation here...
}

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *av = [mapView viewForAnnotation:mapView.userLocation];
    av.enabled = NO;  //disable touch on user location
}
+7
source

All Articles