MKCircle没有更新半径,但它正在翻译 [英] MKCircle is not updating radius but it's translating

查看:209
本文介绍了MKCircle没有更新半径,但它正在翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将MKCicle绘制到MKMapView中。然后,当用户通过滑块更改半径时,我将重新绘制它。我将其删除,然后重新创建它,将其重新添加到地图中。
但是我没有按照我期望的那样做,而是看到MKCircle在地图上进行翻译,保持相同的大小。

I've to draw an MKCicle into an MKMapView. Then I've to re-draw it when user, through a slider, change the radius. I remove it and I re-create it, re-adding it to the map. But instead of do what I'm expecting, I see the MKCircle translating over the map, maintaining the same size.

这是我的代码:

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

NSLog写入控制台右侧值,中心不变并且半径根据用户输入而变化。
但是,同样,MKCircle翻译在西北部。

The NSLog is writing into the console right values, the center doesn't change and the radius changes according to the user input. But, again, the MKCircle translates going on the north-west.

提前致谢,
Samuel Rabini

Thanks in advance, Samuel Rabini

推荐答案

已修复。
我只需添加

Fixed. I just add

self.circleView = nil;

[self.mapView addOverlay:self.circle];

以这种方式工作正常。

塞缪尔

这篇关于MKCircle没有更新半径,但它正在翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆