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.