android 百度地图SDK 获得详细路线信息

package com.example.baidulbs;import android.content.Context;import android.widget.Toast;import com.baidu.location.BDLocation;import com.baidu.location.BDLocationListener;import com.baidu.location.LocationClient;import com.baidu.location.LocationClientOption;import com.baidu.mapapi.map.BaiduMap;import com.baidu.mapapi.map.MapStatus;import com.baidu.mapapi.map.MapStatusUpdateFactory;import com.baidu.mapapi.map.MapView;import com.baidu.mapapi.map.MyLocationData;import com.baidu.mapapi.model.LatLng;import com.baidu.mapapi.search.core.SearchResult;import com.baidu.mapapi.search.route.BikingRouteResult;import com.baidu.mapapi.search.route.DrivingRoutePlanOption;import com.baidu.mapapi.search.route.DrivingRouteResult;import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;import com.baidu.mapapi.search.route.PlanNode;import com.baidu.mapapi.search.route.RoutePlanSearch;import com.baidu.mapapi.search.route.TransitRouteResult;import com.baidu.mapapi.search.route.WalkingRouteResult;import com.example.overlayutl.DrivingRouteOverlay;/** * @author memory_coder * @version 2017-4-3 下午7:43:51 * @application 定位加上路线规划 */public class RouteLbs implements OnGetRoutePlanResultListener{private BaiduMap mbaiDuMap;private Context mcontext;//定位private LocationClient mlocClient;private MyLocationListener myLocListener;private LocationClientOption option;private boolean isFristLoc = true;//路线规划private RoutePlanSearch mRPSearch;private String startNode ;private String cityName ;private String endNode = "政府";public RouteLbs(Context context,MapView mmapView){this.mcontext = context;this.mbaiDuMap = mmapView.getMap();this.option = new LocationClientOption();this.mlocClient = new LocationClient(mcontext);this.myLocListener = new MyLocationListener();this.mRPSearch = RoutePlanSearch.newInstance();}public void start_loc(){mbaiDuMap.setMyLocationEnabled(true);mlocClient.registerLocationListener(myLocListener);        option.setOpenGps(true); // 打开gps        option.setCoorType("bd09ll"); // 设置坐标类型        option.setScanSpan(1000);        option.setAddrType("all");//加上才能获取定位详细地址        mlocClient.setLocOption(option);        mlocClient.start();}public void getDrivePlan(){                //设置起始位置               PlanNode stNode = PlanNode.withCityNameAndPlaceName(cityName,"大学");PlanNode enNode = PlanNode.withCityNameAndPlaceName(cityName, endNode);mRPSearch.drivingSearch(new DrivingRoutePlanOption().from(stNode).to(enNode));               //设置路线监听              mRPSearch.setOnGetRoutePlanResultListener(this);}         //定位服务        private class MyLocationListener implements BDLocationListener{@Overridepublic void onReceiveLocation(BDLocation Blocation){// TODO Auto-generated method stubif(Blocation ==null){Toast.makeText(mcontext, "定位失败", Toast.LENGTH_SHORT).show();}//包装位置信息MyLocationData.Builder builder = new MyLocationData.Builder();builder.accuracy(Blocation.getRadius());builder.direction(100);builder.latitude(Blocation.getLatitude());builder.longitude(Blocation.getLongitude());MyLocationData locData = builder.build();//在地图上显示mbaiDuMap.setMyLocationData(locData);//自动定位if(isFristLoc){isFristLoc = false;LatLng ll = new LatLng(Blocation.getLatitude(), Blocation.getLongitude());MapStatus.Builder mbuilder = new MapStatus.Builder();mbuilder.target(ll).zoom(19.0f);mbaiDuMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mbuilder.build()));}startNode = Blocation.getAddrStr();cityName = Blocation.getCity();/*Toast.makeText(mcontext, Blocation.getAddrStr(),Toast.LENGTH_SHORT).show();*/}}@Overridepublic void onGetBikingRouteResult(BikingRouteResult arg0){// TODO Auto-generated method stub}@Overridepublic void onGetDrivingRouteResult(DrivingRouteResult arg0){// TODO Auto-generated method stubif(arg0==null||arg0.error!=SearchResult.ERRORNO.NO_ERROR){Toast.makeText(mcontext, "null路程", Toast.LENGTH_SHORT).show();}if(arg0.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR){return ;}if(arg0.error== SearchResult.ERRORNO.NO_ERROR){ //int nodeIndex=-1;//这个类在我的百度SDK上是没有的,用于把路线显示出来。我是在网上找的一个类库,如果有需要请加QQ1121767192 备注百度SDkDrivingRouteOverlay overlay = new DrivingRouteOverlay(mbaiDuMap);//overlayManger = overlay;mbaiDuMap.setOnMarkerClickListener(overlay);overlay.setData(arg0.getRouteLines().get(0));overlay.addToMap();overlay.zoomToSpan();}                //循环输出路径信息和距离                //arg0.getRoutelines(0)就是获取第一条路线,一般都有多条路线                for(int i=0;i