0

My app needs to track the user current location periodically. I don't want to use the default blue dot icon. Here is my code for changing it. But it doesn't work.

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[MyLocation class]]) {
        MKAnnotationView *annotationView = (MKAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationView.enabled = YES;
            annotationView.canShowCallout = YES;
            if(annotation != mapView.userLocation){
                annotationView.image = [UIImage imageNamed:@"person.png"];
            }
            else{
                annotationView.image = [UIImage imageNamed:@"selflocation.png"];
            }
            annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        } else {
            annotationView.annotation = annotation;
        }
        return annotationView;
 }

    return nil;
}

I found that the statement:

annotationView.image = [UIImage imageNamed:@"selflocation.png"];

is not even called.

Guru Teja
  • 127
  • 2
  • 13
mmjuns
  • 177
  • 1
  • 11
  • The map view's `userLocation` is of type `MKUserLocation` so the statement you are referring to will never be reached because the outer `if` checks if `annotation` is of type `MyLocation`. So for `userLocation`, the code will jump to the `return nil` statement. Also see http://stackoverflow.com/questions/11432746/custom-annotation-view-for-userlocation-not-moving-the-mapview for issues with using a custom image for MKUserLocation. –  Apr 06 '15 at 02:27
  • Thank you so much...Sorry for my stupid brain... – mmjuns Apr 07 '15 at 05:15

0 Answers0