Draw a circle of 1000m radius around users location in MKMapView Draw a circle of 1000m radius around users location in MKMapView ios ios

Draw a circle of 1000m radius around users location in MKMapView


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;}


An updated version for iOS 8.0 using Swift.

import Foundationimport MapKitclass MapViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate{    var locationManager: CLLocationManager = CLLocationManager()    @IBOutlet var mapView: MKMapView!    override func viewDidLoad() {        super.viewDidLoad()        // We use a predefined location        var location = CLLocation(latitude: 46.7667 as CLLocationDegrees, longitude: 23.58 as CLLocationDegrees)        addRadiusCircle(location)    }    func addRadiusCircle(location: CLLocation){        self.mapView.delegate = self        var circle = MKCircle(centerCoordinate: location.coordinate, radius: 10000 as CLLocationDistance)        self.mapView.addOverlay(circle)    }    func mapView(mapView: MKMapView!, rendererForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {        if overlay is MKCircle {            var circle = MKCircleRenderer(overlay: overlay)            circle.strokeColor = UIColor.redColor()            circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)            circle.lineWidth = 1            return circle        } else {            return nil        }    }}


Swift 3/ Xcode 8 here:

func addRadiusCircle(location: CLLocation){    if let poll = self.selectedPoll {        self.mapView.delegate = self        let circle = MKCircle(center: location.coordinate, radius: 10)        self.mapView.add(circle)    }}func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {    if overlay is MKCircle {        let circle = MKCircleRenderer(overlay: overlay)        circle.strokeColor = UIColor.red        circle.fillColor = UIColor(red: 255, green: 0, blue: 0, alpha: 0.1)        circle.lineWidth = 1        return circle    } else {        return MKPolylineRenderer()    }}

Then call like so:

self.addRadiusCircle(location: CLLocation(latitude: YOUR_LAT_HERE, longitude: YOUR_LNG_HERE))