ios 高德地图 画多边形, 线
//添加路径Polyline
//count 是经纬度点的数量
CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(count* sizeof(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(40, 40, 40, 40) animated:YES];
free(coords);
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(40, 40, 40, 40) animated:YES];
- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id<MAOverlay>)overlay
{
//多边形
if ([overlay isKindOfClass:[MAPolygon class]])
{
MAPolygonRenderer *pol = [[MAPolygonRenderer alloc] initWithPolygon: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 alloc] initWithPolyline:overlay];
polylineRenderer.lineWidth = 6.f;
polylineRenderer.strokeColor = [UIColor blueColor];
return polylineRenderer;
}
return nil;
}