mkmapview MKUserLocation AnnotationView

ios, mkannotation, mkmapview, objective-c

Solution

to show the default annotation for user location just return `nil` for that case, I did it this way:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    // use your custom annotation
    if ([annotation isKindOfClass:[MyAnnotationClass class]]) {
        ...

        return annotationView;
    }

    // use default annotation
    return nil;
}

Problem

I'm trying to create custom annotationviews for the annotations on my map. I'm doing that by adapting the protocol `MKMapViewDelegate` and overwriting the function `mapView:viewForAnnotation:`. It all works, the only problem is that I also have `showsUserLocation` set to `TRUE`, which means that one "Annotation" I get in my `mapView:viewForAnnotation:` method is of the class `MKUserLocation`. I don't want the userlocation annotation to have my custom annotationview, I want that one to show the default userlocation annotationview! How do I return the default userlocation annotationview for the userlocation or exclude it from the annotations (that come in `mapView:viewForAnnotation:`)? I have tried to catch the UserLocation in the `mapView:viewForAnnotation:` method, but I don't know what to return! (In this example I'm returning a standard MKAnnotationView, but that doesn't look like the default UserLocation Annotation (obviously).) ``` if (![[annotation class] isEqual:[MKUserLocation class]]) { MKAnnotationView *view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"customAnnotation"]; // edit the custom view return view; } MKAnnotationView *view = [[MKAnnotationView alloc] init]; return view; ```

Original source