//添加路徑Polylineios
//count 是經緯度點的數量git
CLLocationCoordinate2D *coords = (CLLocationCoordinate2D *)malloc(count* sizeof(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(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;
}