高德地圖    MAMapKit   的使用

高德地圖官方API文檔 地址:http://api.amap.com/Ios/guide#routePlan
1,具體怎麼使用高德地圖api   ,文檔中已經描述的比較詳細了,這裏就不多說了,關於位置定位,標註等
使用的感受還是跟google map api基本類似,

2,現在說說 兩點之間的路線繪製

- (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個方法是路線圖繪製的關鍵,

未完功能待續.......

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章