高德地图步行路线规划代码示例
以下是将高德地图API用于步行路线规划的代码示例:
public void routeSearch(List<LatLonPoint> wayPoints, Integer showFields, final SearchBack searchBack) {
try {
WalkRouteQuery query = new WalkRouteQuery(new RouteSearch.FromAndTo(wayPoints.get(0), wayPoints.get(wayPoints.size() - 1)));
if (showFields != null) query.setShowRouteDetail(showFields);
getRouteSearch().setRouteSearchListener(new RouteSearch.OnRouteSearchListener() {
@Override
public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int code) {
Map<String,Object> map = new HashMap<>();
List<WalkPath> walkPaths = walkRouteResult.getPaths();
List<Map<String,Object>> paths = new ArrayList<>();
for (WalkPath walkPath : walkPaths) {
Map<String,Object> pathMap = new HashMap<>();
String polyline = AMapUtil.convertLatLngListToString(walkPath.getSteps().get(0).getPolyline());
pathMap.put('polyline', polyline);
pathMap.put('distance', walkPath.getDistance());
pathMap.put('duration', walkPath.getDuration());
paths.add(pathMap);
}
map.put('paths', paths);
searchBack.back(code, map);
}
@Override
public void onDriveRouteSearched(DriveRouteResult driveRouteResult, int i) {
// do nothing
}
@Override
public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) {
// do nothing
}
});
getRouteSearch().calculateWalkRouteAsyn(query);
} catch (AMapException e) {
e.printStackTrace();
}
}
请注意,代码中使用了AMapUtil.convertLatLngListToString()方法将经纬度列表转换为字符串形式的路线。您需要根据您的实际情况替换此方法。
原文地址: https://www.cveoy.top/t/topic/pjYx 著作权归作者所有。请勿转载和采集!