gpt4 book ai didi

ios - MKCircle 没有更新半径但它正在翻译

转载 作者:可可西里 更新时间:2023-11-01 05:47:19 26 4
gpt4 key购买 nike

我必须将 MKCicle 绘制到 MKMapView 中。然后我必须在用户通过 slider 更改半径时重新绘制它。我删除它并重新创建它,将它重新添加到 map 中。但是我看到 MKCircle 在 map 上平移,并保持相同的大小,而不是像我期望的那样。

这是我的代码:

- (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 再次翻译为向西北方向前进。

提前致谢,塞缪尔·拉比尼

最佳答案

已修复。我只是添加

self.circleView = nil;

之前

[self.mapView addOverlay:self.circle];

以这种方式它工作正常。

塞缪尔

关于ios - MKCircle 没有更新半径但它正在翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8765805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com