Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawing a MKCircle on a map view
    text
    copied!<p>I need to draw a circle to display the distance around a point that I have plotted. </p> <p>Where should I implement these two lines of code to make it work? I tried putting it in <code>viewWillAppear:</code> but the circle does not appear.</p> <pre><code>[self addCircle:_coordinate]; [self addCircleWithRadius:5.5 addCircleWithCoordinate:_coordinate]; </code></pre> <hr> <pre><code>- (void)addCircle: (CLLocationCoordinate2D)coordinate { // draw the radius circle for the marker double radius = 2000.0; MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate radius:radius]; [circle setTitle:@"background"]; [_mapView addOverlay:circle]; MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:coordinate radius:radius]; [circleLine setTitle:@"line"]; [_mapView addOverlay:circleLine]; } </code></pre> <hr> <pre><code>- (void)addCircleWithRadius:(double)radius addCircleWithCoordinate: (CLLocationCoordinate2D) coordinate { MKCircle *circle = [MKCircle circleWithCenterCoordinate:coordinate radius:radius]; [circle setTitle:@"background"]; [_mapView addOverlay:circle]; MKCircle *circleLine = [MKCircle circleWithCenterCoordinate:coordinate radius:radius]; [circleLine setTitle:@"line"]; [_mapView addOverlay:circleLine]; } </code></pre> <hr> <pre><code>- (void)sliderChanged:(UISlider*)sender { [_mapView removeOverlays:[_mapView overlays]]; double radius = (sender.value * 100); CLLocationCoordinate2D coordinate = self.coordinate; [self addCircleWithRadius:radius addCircleWithCoordinate:coordinate]; } - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id &lt;MKOverlay&gt;)overlay{ MKCircle *circle = overlay; MKCircleView *circleView = [[[MKCircleView alloc] initWithCircle:overlay] autorelease]; if ([circle.title isEqualToString:@"background"]) { //circleView.fillColor = UIColorFromRGB(0x598DD3); circleView.alpha = 0.25; } else { //circleView.strokeColor = UIColorFromRGB(0x5C8AC7); circleView.lineWidth = 2.0; } return circleView; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload