Nikhil Arya
Nikhil Arya

Reputation: 99

How to create a circle overlay over my annotation in Maps using MApkit in iOS?

I want to create a circle overlay over the annotation. I'm using swift 3.0. Any help is appreciated !!

Upvotes: 0

Views: 312

Answers (1)

Pulkit Aggarwal
Pulkit Aggarwal

Reputation: 2672

Try a custom overlay. Add this in viewDidLoad:

MKCircle *circle = [MKCircle circleWithCenterCoordinate:userLocation.coordinate radius:1000];
[map addOverlay:circle];

userLocation can be obtained by storing the MKUserLocationAnnotation as a property. Then, to actually draw the circle, put this in the map view's delegate:

- (MKOverlayRenderer *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
    MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
    circleView.strokeColor = [UIColor redColor];
    circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
    return circleView;
}

Upvotes: 1

Related Questions