ios 高德地图 画多边形, 线

参考资料:
iOS开发经验:高德地图折线或者图形等覆盖物的适配显示-------http://blog.csdn.net/hehai_csdn/article/details/51657804
 
 
 
画图方法
//多边形

 //添加路径Polyline

       //count 是经纬度点的数量

        CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(countsizeof(CLLocationCoordinate2D));

        for (int i = 0; i < count; i++)

        {

            coords[i].latitude = ;//传入  多边形区域的 经纬度

            coords[i].longitude =  ;//传入  多边形区域的 经纬度

        }

        //构造多边形

        MAPolygon *pol = [MAPolygon polygonWithCoordinates:coords count:count];

        //在地图上添加圆

        [_mapView addOverlay: pol];

        [_mapView setVisibleMapRect:pol.boundingMapRect edgePadding:UIEdgeInsetsMake(40404040animated:YES];

        free(coords);

 
//线 画图  linesArr是所有线的集合  存着每一条线的点组合     这里是画多条线
// CommonUtility 类 在高德地图ios demo里 可以找到  

         NSMutableArray *polyLineArray = [NSMutableArray array];//用来存储 画出来的线 MAPolyline对象

        for (NSString *liness in linesArr)

        {

            //添加路径Polyline     count 是组成一条线的 所有点  数量

            CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(count * sizeof(CLLocationCoordinate2D));

            for (int i = 0; i < count; i++)

            {

                coords[i].latitude = ;//一个点的 经纬度

                coords[i].longitude = ;//一个点的 经纬度

            }

            //构造线

            MAPolyline *linepol = [MAPolyline polylineWithCoordinates:coords count:count];

            [polyLineArray addObject:linepol];

            //在地图上添加圆

            [_mapView addOverlay: linepol];

            free(coords);

        }

        MAMapRect  rec = [CommonUtility mapRectForOverlays:polyLineArray];

        [_mapView setVisibleMapRect:rec edgePadding:UIEdgeInsetsMake(40404040animated:YES];

 

 
//多边形 线的  overlay协议

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay

{

//多边形

    if ([overlay isKindOfClass:[MAPolygon class]])

    {

        MAPolygonRenderer *pol = [[MAPolygonRenderer allocinitWithPolygon:overlay];

        pol.lineWidth = 3.f;

        pol.strokeColor =  [UIColor blueColor];

        pol.fillColor = [UIColor colorWithRed:158/255.0 green:230/255.0 blue:252/255.0 alpha:0.5];

        pol.lineDash = NO;//YES表示虚线绘制,NO表示实线绘制

        return pol;

    }else if ([overlay isKindOfClass:[MAPolyline class]])// 线

    {

        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer allocinitWithPolyline:overlay];

        polylineRenderer.lineWidth = 6.f;

        polylineRenderer.strokeColor = [UIColor blueColor];

        return polylineRenderer;

    }

    return nil;

}

 

posted on 2017-02-13 16:21  yuzx  阅读(1650)  评论(0编辑  收藏  举报

导航