本文通過起始點左邊和終點座標來說明介面的使用方法。
1. 進行路徑搜尋
BMKSearch* search = [[BMKSearch alloc] init]; //建立搜尋對象,注意不要釋放該對象search.delegate = self; //設定路徑搜尋結果回調代理為自身BMKPlanNode* currentNode = [[BMKPlanNode alloc] init]; currentNode.pt = theMapView.userLocation.coordinate;currentNode.name = @"aaa"; //注意,這裡不可為空@""BMKPlanNode* poiNode = [[BMKPlanNode alloc] init];poiNode.pt = vehicleLocation.coordinate;poiNode.name = @"bbb";//注意,這裡不可為空@""[search drivingRouteSearch:nil startNode:currentNode endCity:nil endNode:poiNode];//僅以搜尋行車路線為例
2. 通過路線搜尋結果回調來處理路線
- (void)onGetDrivingRouteResult:(BMKPlanResult*)result errorCode:(int)error{ if (error == BMKErrorOk) {BMKRoutePlan* plan = (BMKRoutePlan*)[result.plans objectAtIndex:0]; BMKRoute* route = [plan.routes objectAtIndex:0]; BMKMapPoint* points = malloc(sizeof(CLLocationCoordinate2D) * route.steps.count); for (int i = 0; i < route.steps.count; ++i) { BMKStep* step = [route.steps objectAtIndex:i]; BMKMapPoint point = BMKMapPointForCoordinate(step.pt); //注意這裡的處理方法 points[i] = point; } [mapView removeOverlays:[mapView overlays]]; BMKPolyline* polyLine = [BMKPolyline polylineWithPoints:points count:route.steps.count]; free(points); [mapView addOverlay:polyLine]; }}
3. 在處理路徑回調中處理路徑的顯示
- (BMKOverlayView *)mapView:(BMKMapView *)mapView viewForOverlay:(id <BMKOverlay>)overlay{ BMKOverlayView *result = [[[BMKPolylineView alloc] initWithPolyline:overlay] autorelease]; result.strokeColor = [UIColor blueColor]; result.lineWidth = 4.0; result.lineJoin = kCGLineJoinRound; result.lineCap = kCGLineCapRound; return result;}
iOS基於百度地圖的開發(1)——使用者當前位置
iOS基於百度地圖的開發(2)——擷取POI
iOS基於百度地圖的開發(3)——地址搜尋
iOS基於百度地圖的開發(4)——路徑搜尋
iOS基於百度地圖的開發(5)——核心問題匯總
iOS基於百度地圖的開發(6)——google座標轉換成百度座標
iOS基於百度地圖的開發(7)——百度座標轉換成Google座標