美文网首页
iOS调用百度地图(二)

iOS调用百度地图(二)

作者: LiuffSunny | 来源:发表于2019-08-05 18:20 被阅读0次

可以借助title属性来绘制多个电子围栏

//添加预警区域覆盖物
- (void)addWarningOverlayViewAndAnnotationWithModel:(SiteelectFenceModel *)model {
    if ([model.electFenceType isEqualToString:@"1"]) {
        // 添加圆形覆盖物
        int electRadius = 100;
        if (![NSString isNull:model.electRadius]) {
            if ([model.electRadius intValue] < 30) {
                electRadius = 30;
            }else{
                electRadius = [model.electRadius intValue];
            }
        }
        BMKCircle* warningcircle;
        CLLocationCoordinate2D coor = CLLocationCoordinate2DMake([model.electCenter.lat doubleValue], [model.electCenter.lon doubleValue]);
        warningcircle = [BMKCircle circleWithCenterCoordinate:coor radius:electRadius];
        warningcircle.title = WarningTag;
        [_mapView addOverlay:warningcircle];
    }else if ([model.electFenceType isEqualToString:@"2"]){
        BMKPolygon *warningpolygon;
        // 添加多边形覆盖物
        CLLocationCoordinate2D coords[model.coordinateList.count];
        for (int i = 0; i < model.coordinateList.count; i ++) {
            SiteLocationModel *lomodel = model.coordinateList[i];
            CLLocationCoordinate2D coord = CLLocationCoordinate2DMake([lomodel.lat doubleValue], [lomodel.lon doubleValue]);
            coords[i] = coord;
        }
        warningpolygon = [BMKPolygon polygonWithCoordinates:coords count:model.coordinateList.count];
        warningpolygon.title = WarningTag;
        [_mapView addOverlay:warningpolygon];
    }else{//不去绘制
    }
    // 打点
    [self addLocationAnnotationWithModel:model];
}

大头针打点 单个

  • (void)addLocationAnnotationWithModel:(SiteelectFenceModel *)model {
    BMKPointAnnotation *annotation = [[BMKPointAnnotation alloc] init];
    annotation.title = WarningTag;
    [_mapView addAnnotation:annotation];
    _annotation = annotation;
    CLLocationCoordinate2D coor = CLLocationCoordinate2DMake([model.lat doubleValue], [model.lon doubleValue]);
    _annotation.coordinate = coor;
    }

代理方法

//根据overlay生成对应的View

  • (BMKOverlayView *)mapView:(BMKMapView )mapView viewForOverlay:(id <BMKOverlay>)overlay
    {
    if ([overlay isKindOfClass:[BMKCircle class]])
    {
    BMKCircleView
    circleView = [[BMKCircleView alloc] initWithOverlay:overlay];
    if ([overlay.title isEqual:WarningTag]) {
    circleView.fillColor = [UIColor colorWithHex:0xFF0000 alpha:0.2];
    circleView.strokeColor = [UIColor colorWithHex:0xFF0000 alpha:1];
    }else
    {
    circleView.fillColor = [UIColor colorWithHex:0x6FB1FF alpha:0.2];
    circleView.strokeColor = [UIColor colorWithHex:0x6FB1FF alpha:1];
    }
    circleView.lineWidth = 0.5;
    return circleView;
    }

    if ([overlay isKindOfClass:[BMKPolygon class]])
    {
    BMKPolygonView* polygonView = [[BMKPolygonView alloc] initWithOverlay:overlay];
    if ([overlay.title isEqual:WarningTag]) {
    polygonView.fillColor = [UIColor colorWithHex:0xFF0000 alpha:0.2];
    polygonView.strokeColor = [UIColor colorWithHex:0xFF0000 alpha:1];
    }else{
    polygonView.strokeColor = [UIColor colorWithHex:0x6FB1FF alpha:1];
    polygonView.fillColor = [UIColor colorWithHex:0x6FB1FF alpha:0.2];
    }
    polygonView.lineWidth = 0.5;
    // polygonView.lineDash = (overlay == polygon2);
    return polygonView;
    }

    return nil;
    }

#大头针图标显示和区分的代理方法
#pragma mark - BMKMapViewDelegate
/**
 根据anntation生成对应的annotationView
 
 @param mapView 地图View
 @param annotation 指定的标注
 @return 生成的标注View
 */
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation {
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
        newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
        newAnnotationView.animatesDrop = NO;// 设置该标注点动画显示
        newAnnotationView.annotation=annotation;
        [newAnnotationView.paopaoView removeFromSuperview];
        //    newAnnotationView.tag = [annotation.subtitle integerValue];

        NSString *imagename;
        if ([annotation.title isEqual:WarningTag]) {
            //预警小图标
            imagename = @"icon_jingzhi_42*42_3.6";
        }else{
            if (![NSString isNull:self.showView.siteModel.addressType] && ![NSString isNull:self.showView.siteModel.markColor]) {
                imagename = [NSString stringWithFormat:@"icon_%@_%@_big",self.showView.siteModel.addressType,self.showView.siteModel.markColor];
            }else
            {
                if ([self.showView.siteModel.isExists isEqualToString:@"1"]) {
                    // 是个库区
                    imagename = [NSString stringWithFormat:@"icon_dingwei1_m_90x106_3.2"];
                }else
                {
                    imagename = [NSString stringWithFormat:@"icon_tanhao_m_90x106_3.2"];
                }
            }
        }
        UIImage *icoImage = [UIImage imageNamed:imagename];
        newAnnotationView.image = icoImage;   //把大头针换成别的图片
        [self.BkAnnotionViews addObject:newAnnotationView];
        newAnnotationView.frame = CGRectMake(0, 0, icoImage.size.width, icoImage.size.height);
        
        UIView *popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 260, 124)];
        BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];
        pView.hidden = YES;
        pView.frame = CGRectMake(0, 0, 260, 124);
        ((BMKPinAnnotationView*)newAnnotationView).paopaoView = nil;
        ((BMKPinAnnotationView*)newAnnotationView).paopaoView = pView;
        
        return newAnnotationView;
    }
    return nil;
}

相关文章

  • iOS调用百度地图(二)

    可以借助title属性来绘制多个电子围栏 大头针打点 单个 (void)addLocationAnnotation...

  • app调用百度地图导航或者高德地图导航

    一.百度导航调用方法: 更多请查看百度官方文档走,去看看 二.高德地图导航调用方式 高德地图更多信息请看官方文档走...

  • 百度地图API geolocation三次不允许定位后再次弹出用

    问题描述 手机端h5页面调用百度地图获取地理位置的API,iOS手机上效果会提示是否允许百度地图访问开启定位服务,...

  • 调用地图app或网页版地图

    通过链接调用百度地图app或者高德地图app 百度地图 "http://api.map...

  • 百度地图调用api

    1.注册百度地图用户 2.百度地图中创建应用,获取ak值 3.调用 (1)调用百度地图api 在应用中填写自己获取...

  • RN-地图导航

    调起百度网页地图路径导航 调起高德网页地图路径导航 iOS调起百度APP地图路径导航 iOS调起高德app地图路径...

  • iOS百度地图使用时不弹出系统定位权限框

    整理下在使用百度地图的过程中新发现的问题,在首页中我正常调用了百度地图iOS的API,代理也正常返回,但是在使用过...

  • 地图

    Android调用第三方地图,高德地图,百度地图!

  • 百度地图API调用

    调用百度地图的API可以非常方便的实现我们需要的地图的功能,今天研究了一下调用百度地图API,显示定位信息、地图标...

  • 地图集成调研

    地图集成调研 主要地图API有百度地图、高德地图、腾讯地图、搜狗地图(android、IOS暂不开放)。 百度地图...

网友评论

      本文标题:iOS调用百度地图(二)

      本文链接:https://www.haomeiwen.com/subject/jjxmdctx.html