【发布时间】:2020-06-28 12:02:14
【问题描述】:
我正在尝试在地图视图的中心渲染一个圆圈。我还在地图视图上显示用户的当前位置,并将地图的中心设置为那里。不过,这两个没有排队。
这是我建立圈子的地方:
[self.mapView setShowsUserLocation:YES];
CAShapeLayer *circle = [CAShapeLayer layer];
int radius = 50;
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
// Set position of the circle.
// We use the frame of the mapview subtracted by circle radius to determine the center
circle.position = CGPointMake(CGRectGetMidX(self.mapView.frame)-radius,
CGRectGetMidY(self.mapView.frame)-radius);
circle.fillColor = [[UIColor alloc] initWithRed:0.5 green:0.5 blue:0.6 alpha:0.3].CGColor;
circle.strokeColor = [UIColor blackColor].CGColor;
circle.lineWidth = 1;
// Add to parent layer
[self.mapView.layer addSublayer:circle];
// Add 'crosshair'
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor blackColor];
view.frame = CGRectMake(0, 0, 5, 5);
[self.mapView addSubview:view];
view.center = self.mapView.center;
在 didUpdateUserLocation 委托方法中我有:
[self.mapView setCenterCoordinate:userLocation.coordinate];
这是模拟器上的样子。
我最终希望允许用户平移和选择地图的一个区域,但现在我不确定我的地图中心坐标是否与我的圆心重合。有什么帮助吗?谢谢!
【问题讨论】:
标签: ios objective-c mkmapview