问题
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?
回答1:
Unfortunately you cannot simply alter the behaviour of the standard annotation; you need to take over display of the annotation view yourself.
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.
You can code something like:
- (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.
来源:https://stackoverflow.com/questions/38431170/how-to-increase-the-radius-of-userlocation-annotation-in-mapkit