我需要繪製一個圓來顯示我繪製的點周圍的距離。在地圖視圖上繪製MKCircle
我應該在哪裏實現這兩行代碼才能使其工作?我試圖把它放在viewWillAppear:
,但圓圈沒有出現。
[self addCircle:_coordinate];
[self addCircleWithRadius:5.5 addCircleWithCoordinate:_coordinate];
- (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];
}
- (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];
}
- (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 <MKOverlay>)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;
}
請格式化您的代碼。謝謝。 –
謝謝deepak ...對我的問題的任何建議? –
什麼是_coordinate?你確定'_mapView'設置了嗎?我的意思是什麼'NSLog(@「%@」,_mapView);'打印? –