- (void)addline:(MARoute*)route{// 添加路線圖
[annotions removeAllObjects];
for(MARoute *ret in poiArray){//poiArray 爲路線集合,循環分段繪製
NSArray *routes =[ret.coor componentsSeparatedByString:@","];
int n =[routes count]/2 ;
CLLocationCoordinate2D points[n];
for (int i = 0; i < n; i++) {
CLLocationCoordinate2D coords;
coords.longitude=[[routes objectAtIndex:2*i] floatValue];
coords.latitude=[[routes objectAtIndex:2*i+1] floatValue];
CLLocationDegrees lat = coords.latitude;
CLLocationDegrees longit = coords.longitude;
points[i] = CLLocationCoordinate2DMake(lat, longit);
}
MAPolyline *lineOne = [MAPolyline polylineWithCoordinates:points count:n];
[mamapView addOverlay:lineOne];// 向地圖窗口添加Overlay,需要實現MAMapViewDelegate的-mapView:viewForOverlay:函數來生成標註對應的View
}
- (MAOverlayView *)mapView:(MAMapView *)mapView viewForOverlay:(id )overlay{
if ([overlay isKindOfClass:[MAPolyline class]]){
MAPolylineView *lineView = [[[MAPolylineView alloc] initWithPolyline: overlay]autorelease];
lineView.lineWidth = 5.0f;
lineView.strokeColor = [UIColor redColor];
lineView.fillColor = [UIColor blackColor];
return lineView;
}
return nil;
}
以上2個方法是路線圖繪製的關鍵,
未完功能待續.......