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

前端 未结 8 2041
死守一世寂寞
死守一世寂寞 2020-11-29 17:18

(Using iOS 5 and Xcode 4.2)

I have an MKMapView and want to draw a circle of 1000m radius around the user location.

On the surface it would seem tha

8条回答
  •  猫巷女王i
    2020-11-29 18:01

    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 )overlay
    {
        MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
        circleView.strokeColor = [UIColor redColor];
        circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
        return circleView;
    }
    

提交回复
热议问题