高德地图AndroidSDK 路线规划详情获取

我们用高德地图SDK在进行路径规划后,除了将线路添加到地图时候,往往还需要获取线路的详细描述信息,比方说路线长度,所需时间、路线的每一段情况等,就如高度地图这样:

 高德地图AndroidSDK 路线规划详情获取

我们就简答实现下这个功能,首先进行公交线路查询(不清楚的同学可以看下demo),在查询结果中进行处理:

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
if (busRouteResult != null && busRouteResult.getPaths() != null
 
                  && busRouteResult.getPaths().size() > 0) {
 
 
              // 以推荐线路的第一条数据为例进行处理
 
              BusPath busPath = busRouteResult.getPaths().get(0);
 
              // 分别获取公交线路距离,步行距离,整个线路距离
 
              String routeInfo = "公交路线长度:" + busPath.getBusDistance()
 
                     + "  步行 长度" + busPath.getWalkDistance() + "  线路长度:"
 
                     + busPath.getDistance() + "\n";
 
  
 
              List<BusStep> busSteps = busPath.getSteps();
 
              // 获取每一段换乘所需的步行距离,起始终止站点,经过的站数(不包括起始和终点站),距离和所需时间
 
              for (BusStep busStep : busSteps) {
 
                  if (busStep.getWalk() != null) {
 
                     RouteBusWalkItem walkPath = busStep.getWalk();
 
                     routeInfo = routeInfo + "需要步行大约"
 
                            + Math.round(walkPath.getDuration() / 60)
 
                            + "分钟,步行" + walkPath.getDistance() + "米\n";
 
                  }
 
                  if (busStep.getBusLine() != null) {
 
                     RouteBusLineItem busLineItem = busStep.getBusLine();
 
                     routeInfo = routeInfo
 
                            + "乘坐"
 
                            + busLineItem.getBusLineName()
 
                            + "需要大约"
 
                            + Math.round(busLineItem.getDuration() / 60)
 
                            + "分钟,大约"
 
                            + busLineItem.getDistance()
 
                            + "米,经过"
 
                            + busLineItem.getPassStationNum()
 
                            + "站,从"
 
                            + busLineItem.getDepartureBusStation()
 
                                   .getBusStationName()
 
                            + "上车,从"
 
                            + busLineItem.getArrivalBusStation()
 
                                   .getBusStationName() + "下车\n";
 
                  }
 
  
 
              }
 
              mRouteInfoText.setText(routeInfo);

  

效果如下图所示:

 高德地图AndroidSDK 路线规划详情获取

同样的可以对步行、行车路线进行详细信息获取。具体代码(替换key)和apk见附件

高德地图AndroidSDK 路线规划详情获取,布布扣,bubuko.com

高德地图AndroidSDK 路线规划详情获取

上一篇:高德Android SDK 2d地图zoomlevel Bug一种解决方案


下一篇:iOS 解析html数据