百度地图点位画圈选择 以及划线选择 BMKGroundOverlay(CAShapeLayer+UIBezierPath)

 

一.最基础的地图覆盖物

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就是数组的大小
   
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值