获取一条公交上的所有站点 获取两站直接的线路

百度地图-获取一条公交上的所有站点 获取两站直接的线路:

mSearch = new MKSearch();// 搜索服务类            mSearch.init(mapManager, new MKSearchListener() {                  public void onGetPoiResult(MKPoiResult res, int type, int error) {                   // 错误号可参考MKEvent中的定义                    if (error != 0 || res == null) {                       Toast.makeText(BusRouteSysActivity.this"抱歉,未找到结果",                               Toast.LENGTH_LONG).show();                       return;                   }                      String allStations = null;                      MKPoiInfo curPoi = null;                   int totalPoiNum = res.getNumPois();                   for (int idx = 0; idx < totalPoiNum; idx++) {                       Log.d("busline""the busline is " + idx);                       curPoi = res.getPoi(idx);                       allStations += curPoi.name;//把所有站点放到allStation                           Log.i("allStation", allStations);                       if (2 == curPoi.ePoiType) {                           break;                       }                   }                      mSearch.busLineSearch(mCityName, curPoi.uid);               }                  public void onGetTransitRouteResult(MKTransitRouteResult result,                       int iError) {                   if (result == null) {                       return;                   }                   Log.d("liuyq""公交换乘方案数:" + result.getNumPlan());                      TransitOverlay routeOverlay = new TransitOverlay(                           BusRouteSysActivity.this, mapView);                   // 此处仅展示一个方案作为示例                    routeOverlay.setData(result.getPlan(0));                   mapView.getOverlays().clear();                   mapView.getOverlays().add(routeOverlay);                   mapView.invalidate();                      ResStringList = new ArrayList<String>();                   for (int i = 0; i < result.getNumPlan(); i++) {                       // 公交换乘方案详情类                        MKTransitRoutePlan routePlan = result.getPlan(i);                       // 再根据MKTransitRoutePlan类提供的方法去获取具体的换乘信息(省略)                        int lineNum = routePlan.getNumLines();                          Log.d("1111111""方案" + (i + 1) + "包含的公交线路段数:" + lineNum);                          StringBuffer reStringBuffer = new StringBuffer("");// 结果句子                        String keyword = "";// 先 再 最后                        for (int j = 0; j < lineNum; j++) {                           MKLine mkLine = routePlan.getLine(j);                              MKPoiInfo onstopInfo = mkLine.getGetOnStop();                           MKPoiInfo offstopInfo = mkLine.getGetOffStop();                              String lineName = mkLine.getTitle();// 线路名                            String startPointName = onstopInfo.name;// 起点名                            String endPointName = offstopInfo.name;// 终点名                            String endword = "";                           if (j == 0) {                               keyword = "先";                           } else if (j == lineNum - 1) {                               keyword = ",最后";                               endword = "\n\n";                           } else {                               keyword = ",再";                           }                              reStringBuffer.append(keyword + "从 " + startPointName                                   + " 上车,乘坐" + lineName + "路,在 " + endPointName                                   + "下车" + endword);                              Log.d(TAG, "第" + (j + 1) + "段起点名称:" + startPointName);                           Log.d(TAG, "第" + (j + 1) + "段终点名称:" + endPointName);                       }                       // 如果不重复 就加入                        if (!ResStringList.contains(reStringBuffer.toString())) {                           ResStringList.add(reStringBuffer.toString());                       }                   }                   allResults = "";                   for (String s : ResStringList) {                       System.out.println(s);                       allResults += s;                   }                   mapView.getController().animateTo(result.getStart().pt);               }                  public void onGetDrivingRouteResult(MKDrivingRouteResult res,                       int error) {               }                  public void onGetWalkingRouteResult(MKWalkingRouteResult res,                       int error) {               }                  public void onGetBusDetailResult(MKBusLineResult result, int iError) {                   if (iError != 0 || result == null) {                       Toast.makeText(BusRouteSysActivity.this"抱歉,未找到结果",                               Toast.LENGTH_LONG).show();                       return;                   }                   allResults = "";                   for (int i = 0; i < result.getBusRoute().getNumSteps(); i++) {                          allResults += result.getStation(i).getContent() + "-->";                       textViewTop.setText(allResults);                   }                      RouteOverlay routeOverlay = new RouteOverlay(                           BusRouteSysActivity.this, mapView);                   // 此处仅展示一个方案作为示例                    routeOverlay.setData(result.getBusRoute());                   mapView.getOverlays().clear();                   mapView.getOverlays().add(routeOverlay);                   mapView.invalidate();                   mapView.getController().animateTo(                           result.getBusRoute().getStart());               }                  @Override               public void onGetAddrResult(MKAddrInfo arg0, int arg1) {                   // TODO Auto-generated method stub                   }              });  

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ppfxf.html