2012-01-06 18 views
4

私はMKCicleをMKMapViewに描画しました。次に、スライダを使って半径を変更したときに、再度描画する必要があります。私はそれを削除し、再作成してマップに追加し直します。 しかし、私が期待していることではなく、MKCircleが同じサイズを維持しながら地図上を翻訳しているのが分かります。MKCircleは半径を更新していませんが、それは翻訳しています

は、ここに私のコードです:のNSLogは、コンソール右値に書き込んで

- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id)overlay 
{ 
    MKOverlayView* overlayView = nil; 

    if(overlay == self.circle) 
    { 
     //if we have not yet created an overlay view for this overlay, create it now. 
     if(nil == self.circleView) 
     { 
      self.circleView = [[[MKCircleView alloc] initWithCircle:self.circle] autorelease]; 
      self.circleView.fillColor = [UIColor blueColor]; 
      self.circleView.strokeColor = [UIColor blueColor]; 
      self.circleView.alpha = 50; 
      self.circleView.lineWidth = 2; 
     } 

     overlayView = self.circleView; 
    } 

    return overlayView; 
} 

-(void)drawPolygonWithLocation 
{ 
    [self.mapView removeOverlay: self.circle]; 

    MKCoordinateRegion region; 
    region.center.latitude = self.geofenceLocation.latitude; 
    region.center.longitude = self.geofenceLocation.longitude; 
    region.span.latitudeDelta = 0.005; 
    region.span.longitudeDelta = 0.005; 

    MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits: region]; 
    [self.mapView setRegion:adjustedRegion animated:TRUE]; 

    self.radius = (double)(slRadius.value); 
    NSLog(@"Raggio: %f", self.radius); 
    NSLog(@"Lat: %f, Lon: %f", region.center.latitude, region.center.longitude); 
    self.circle = [MKCircle circleWithCenterCoordinate:self.geofenceLocation.coordinate radius: self.radius]; 
    NSLog(@"CIRCLE: radius %f Lat: %f, Lon: %f", self.circle.radius, self.circle.coordinate.latitude, self.circle.coordinate.longitude); 

    [self.mapView addOverlay:self.circle]; 
} 

-(IBAction)updateRadius:(id)sender 
{ 
    [self drawPolygonWithLocation]; 
} 

は、センターが変わらないと半径は、ユーザの入力に応じて変化します。 しかし、もう一度、MKCircleは北西に移動します。事前に

おかげで、固定 サミュエルRabini

答えて

3

。 私はちょうどそれが正常に動作し、このように

[self.mapView addOverlay:self.circle]; 

self.circleView = nil; 

を追加します。

サミュエル

関連する問題