、
一.最基础的地图覆盖物
1>画圈 BMKCircle
2>画线BMKPolyline
3>画多边形BMKPolygon
至于判断点是否在圈内系统提供了方法 这里不再赘述
二、这里主要说BMKGroundOverlay(CAShapeLayer+UIBezierPath)
#pragma mark -开始圈选
-(void)startCircleSelect{
if (self.touchView==nil) {
self.touchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.mapView.width, self.mapView.height)];
self.touchView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2];
[self.mapView addSubview:self.touchView];
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//移除点位的所有数据
[self.coor2dArray removeAllObjects];
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//self.touchView 是画板的view 大小等于 地图的大小
if (self.touchView==nil) {
return;
}
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self.touchView];
//将触摸点 point 转换为经纬度坐标
CLLocationCoordinate2D pointCoor2d= [self.mapView convertPoint:point toCoordinateFromView:self.touchView];
ZTOverlayModel *tempModel = [[ZTOverlayModel alloc]init];
tempModel.point = point;
tempModel.coor2d = pointCoor2d;
//数据去重
if(self.coor2dArray.count==0){
[self.coor2dArray addObject:tempModel];
}else{
ZTOverlayModel *lastModel = self.coor2dArray.lastObject;
if (lastModel.coor2d.longitude != pointCoor2d.longitude || lastModel.coor2d.latitude != pointCoor2d.latitude) {
[self.coor2dArray addObject:tempModel];
}
}
//画一条地图上的BMKPolyline 线型覆盖物
NSInteger size = [self.coor2dArray count];
//大于三的时候才添加
if (size >= 3) {
//动态分配数组
CLLocationCoordinate2D * coords = (CLLocationCoordinate2D *)malloc(sizeof(CLLocationCoordinate2D)*size);//size就是数组的大小