【发布时间】:2018-12-23 21:53:07
【问题描述】:
所以 Mapbox 为 Android 提供了一个很棒的 Navigation SDK,我一直在尝试创建自己的路线,将每个点表示为 Geojson 文件中的一个要素,然后将它们传递给 MapMatching 模块以获取路线然后我可以传递给导航引擎。
我的解决方案演变为两个主要部分。第一个涉及遍历我希望导航通过的点,将它们作为输入添加到 MapboxMapMatching.builder() 的 .coordinates 元素,然后将其转换为 .toDirectionRoute();根据 Mapbox 说明和此处的示例:https://www.mapbox.com/android-docs/java/examples/use-map-matching/
private void getWaypointRoute(List<Point> features) {
originPosition = features.get(0);
destinationPosition = features.get(features.size() - 1);
MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(features)
.steps(true) // Setting this will determine whether to return steps and turn-by-turn instructions.
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>() {
@Override
public void onResponse(Call<MapMatchingResponse> call, Response<MapMatchingResponse> response) {
if (response.body() == null) {
Log.e(TAG, "Map matching has failed.");
return;
}
if (response.isSuccessful()) {
currentRoute = response.body().matchings().get(0).toDirectionRoute();
第二点只是将“currentRoute”传递给 NavigationLauncher,如下所示:
NavigationLauncherOptions options = NavigationLauncherOptions.builder()
.origin(origin)
.destination(destination)
.directionsRoute(currentRoute)
.shouldSimulateRoute(simulateRoute)
.enableOffRouteDetection(false)
.build();
// Call this method with Context from within an Activity
NavigationLauncher.startNavigation(MainActivity.this, options);
可以在此处查看路线示例Android Simulator Snapshot with Route 。路线上的每个点都是一个交叉点,并且对应于我的 GeoJson 文件中的一个特征。当我启动导航时,问题就出现了。每次,无论是在模拟器中还是在真实设备上,每个点都被解释为一个目的地,因此语音命令会显示“您已到达您的第一个(第二个、第三个等)目的地”。我觉得这很烦人,因为我希望有一条带有目的地的路线,仅此而已。我只想知道这一点,所以我有自己的自定义路径,而不是路由应用程序通常返回的最短路径。我试图通过关闭 voiceInstructions 来避免这个问题,但随后系统变得很糟糕,导航屏幕移动到 lat, lng (0,0),这几乎是非洲西部的某个地方。任何有关如何解决此问题的帮助将不胜感激,我很乐意为提供正确答案的人购买一两杯啤酒。我也联系了 Mapbox 支持,但我们还没有找到问题的答案,所以我要求他们在他们的工程团队内部升级它,我相信,虽然我要解决的问题并不少见,但仍然不是开发人员进行了非常多的测试。干杯!
【问题讨论】:
标签: android mobile routing navigation mapbox