如何将MKMapView的用户位置蓝点更改为所选图像? [英] How to change MKMapView's user-location blue dot to an image of choice?
问题描述
是否可以更改蓝点,表示用户在<$中的位置c $ c> MKMapView 到图像?例如一辆小汽车或任何 .png
图片?
Is it possible to change the blue dot which indicates the user's location in MKMapView
to an image? For example a little car or any .png
image?
推荐答案
在 viewForAnnotation中 MKMapViewDelegate 的方法可能你会得到这样的代码。
In the viewForAnnotation: method of MKMapViewDelegate probably you would be having the code like this.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if (annotation == mapView.userLocation) return nil;
...
如果 nil >注释是 userLocation ,让 mapView 显示蓝点&圆圈动画。为了显示 userLocation 的自定义注释,只需删除行 return nil;
并在那里进行自定义。
We return nil if the annotation is userLocation to let the mapView display the blue dot & circle animation. In order to show our custom annotation for userLocation just remove the line return nil;
and do your customization there.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString* AnnotationIdentifier = @"Annotation";
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if (!pinView) {
MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
if (annotation == mapView.userLocation){
customPinView.image = [UIImage imageNamed:@"myCarImage.png"];
}
else{
customPinView.image = [UIImage imageNamed:@"mySomeOtherImage.png"];
}
customPinView.animatesDrop = NO;
customPinView.canShowCallout = YES;
return customPinView;
} else {
pinView.annotation = annotation;
}
return pinView;
}
这篇关于如何将MKMapView的用户位置蓝点更改为所选图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!