ios 高德地圖 畫多邊形, 線

參考資料:
iOS開發經驗:高德地圖折線或者圖形等覆蓋物的適配顯示-------http://blog.csdn.net/hehai_csdn/article/details/51657804
 
 
 
畫圖方法
//多邊形

 //添加路徑Polylineios

       //count 是經緯度點的數量git

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

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

        {orm

            coords[i].latitude = ;//傳入  多邊形區域的 經緯度對象

            coords[i].longitude =  ;//傳入  多邊形區域的 經緯度blog

        }開發

        //構造多邊形get

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

        //在地圖上添加圓

        [_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;

}

相關文章
相關標籤/搜索