我的应用需要定期跟踪用户当前位置。我不想使用默认的蓝点图标。这是我更改它的代码。但它不起作用。
- (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;
}
我发现声明:
annotationView.image = [UIImage imageNamed:@"selflocation.png"];
甚至没有被召唤。