我正在使用 Mapbox 构建导航应用。 我想获取一些信息,例如导航期间的速度限制。 谁能帮我吗?
示例代码:-
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.directionsRoute(currentRoute)
.shouldSimulateRoute(false)
.build();
NavigationLauncher.startNavigation(getActivity(), options);
答案 0 :(得分:0)
在https://docs.mapbox.com/help/how-mapbox-works/directions/#travel-times中,您似乎可以通过openstreetmap中的https://wiki.openstreetmap.org/wiki/Key:maxspeed访问速度限制。这就是Mapbox在其路由器内部使用的方式。
答案 1 :(得分:0)
由于还没有人发布实际的“复制粘贴”答案,而且我在实现工作代码方面付出了很多努力,我将在这里发布我的答案。
首先,您需要在请求中添加 maxspeed
注释。你可以这样做:
final RouteOptions.Builder builder = RouteOptions
.builder()
.accessToken(Mapbox.getAccessToken())
// more optionst
.overview(OVERVIEW_FULL) // required
.annotationsList(Arrays.asList(DirectionsCriteria.ANNOTATION_MAXSPEED)); // obviously required
然后您需要将 RouteProgressObserver
添加到您的 NavigationViewOptions
在 RouteProgressObserver
中,您现在应该能够使用以下代码获得最大速度列表(每个路线坐标之间的速度):
@Override
public void onRouteProgressChanged(@NotNull RouteProgress routeProgress) {
List<MaxSpeed> maxspeed = routeProgress
.getCurrentLegProgress()
.getRouteLeg()
.annotation()
.maxspeed();
}
希望对某人有所帮助)