如何增加Mapkit中userLocation注释的半径 [英] How to Increase the Radius of userLocation Annotation in Mapkit

查看:151
本文介绍了如何增加Mapkit中userLocation注释的半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用获取用户权限并将地图移动到该位置。默认情况下,在该位置 MapKit 添加一个生成一些脉冲的蓝色图标。
我已经搜索过但我发现如何添加一个1000米的圆圈用户位置。我不希望这样。你可以说我想要自定义 userLocation 默认注释。它生成的蓝色脉冲我希望增加 radius 。当此蓝色脉冲点击自定义注释时,应该触发一个方法。那么如何实现呢?

My app takes user permission and move the map to the location. And at that position by default MapKit add a blue icon which is generating some pulse.
I've searched around but I found how to add a 1000m circle around userLocation. I don't want that. You can say I'm looking to customize the userLocation default annotation. The blue pulse it generates I want to increase that radius. And when this blue pulse hits a custom annotation there should be a method triggered. So how to achieve that?

推荐答案

不幸的是,你不能简单地改变标准注释的行为;您需要自己接管注释视图的显示。

Unfortunately you cannot simply alter the behaviour of the standard annotation; you need to take over display of the annotation view yourself.

用户位置是类型 MKUserLocation 的地图注释。如果您实现 MKMapViewDelegate 方法 viewForAnnotation 并且地图显示用户的位置,那么将调用委托方法 MKUserLocation 的实例 - 您的责任是返回 nil ,在这种情况下,将显示标准注释视图,或者返回一个 MKAnnotationView 的实例,它将被显示。

The user location is a map annotation of type MKUserLocation. If you implement the MKMapViewDelegate method viewForAnnotation and the map is displaying the user's location then the delegate method will be called with an instance of MKUserLocation - your responsibility is to either return nil, in which case the standard annotation view will be displayed, or return an instance of MKAnnotationView which will be displayed instead.

您可以编写如下代码:

- (MKAnnotationView *)mapView:(MKMapView *)mapView
        viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        return [[MyPulsingViewAnnotation alloc] initWithUserLocation:annotation];
    }

    return nil;
}

至于'脉冲'与另一个注释相交时执行某些动画,你会需要将其他注释位置传递到脉冲视图并在运行动画时检查坐标。

As for performing some animation when the 'pulse' intersects another annotation, you will need to pass the other annotation locations to your pulsing view and check the coordinates when you run the animation.

这篇关于如何增加Mapkit中userLocation注释的半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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