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

这篇博客主要介绍了在iOS开发中使用百度地图SDK进行地图覆盖物的绘制,包括画圈(BMKCircle)、画线(BMKPolyline)和画多边形(BMKPolygon),并提到了利用CAShapeLayer+UIBezierPath实现BMKGroundOverlay的功能。此外,还提及了如何判断点是否在绘制的曲线路径上,给出了相关思路的参考资料链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

一.最基础的地图覆盖物

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就是数组的大小
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值