1

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?

Chaudhry Talha
  • 7,231
  • 11
  • 67
  • 116

1 Answers1

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.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Have you personally done this? Sounds like a hack. Apple makes us do this every time .... – denis631 Jul 19 '17 at 20:03
  • Why is it a "hack". There is no capability to modify the appearance of the standard annotation. Either you want Apple's standard annotation view or you want something different. If you want something different you need to provide your own view. – Paulw11 Jul 19 '17 at 20:31
  • all I want is just to increase the radius of the user location annotation circle, but I can not do that, so I have to create my own overlay, hence a hack. – denis631 Jul 19 '17 at 21:01