我正在添加一个自定义注释以及用户的当前位置默认气泡注释,但用户位置注释在某个时间不关注地图视图后更改为另一个自定义位置。
我的 viewForAnnotation 方法是:
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
NSString* annotationidentifier = @"customview";
CustomAnnotationView *customannotationview = (CustomAnnotationView*) [self.mapview dequeueReusableAnnotationViewWithIdentifier:annotationidentifier];
if([annotation isKindOfClass:[MKUserLocation class]])
{
customannotationview = [[CustomAnnotationView alloc] initWithAnnotationWithImage:annotation reuseIdentifier:annotationidentifier annotationviewimage:[UIImage imageNamed:@"location pin28.png"]];
customannotationview.canShowCallout = YES;
return customannotationview;
}
else if(![annotation isKindOfClass:[MKUserLocation class]] && annotation != _mapview.userLocation && (annotation.coordinate.latitude != _locationmanager.location.coordinate.latitude && annotation.coordinate.longitude != _locationmanager.location.coordinate.longitude))
{
customannotationview = [[CustomAnnotationView alloc] initWithAnnotationWithImage:annotation reuseIdentifier:annotationidentifier annotationviewimage:[UIImage imageNamed:@"image1.png"]];
return customannotationview;
}
return customannotationview;
}
我已经在自定义注释中添加了条件,但是如果用户位置在某些时候失去焦点,它仍然会在一段时间后更改为 image1.png