如何将MKMapView的用户位置蓝点更改为所选图像? [英] How to change MKMapView's user-location blue dot to an image of choice?

查看:314
本文介绍了如何将MKMapView的用户位置蓝点更改为所选图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改蓝点,表示用户在<$中的位置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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆