gpt4 book ai didi

android - 通过自定义路线进行 Mapbox 导航

转载 作者:行者123 更新时间:2023-11-30 05:09:56 25 4
gpt4 key购买 nike

所以 Mapbox 为 Android 提供了一个很棒的导航 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 文件中的一个要素。当我启动导航时,问题就出现了。每次,无论是在模拟器中还是在真实设备上,每个点都被解释为目的地,因此语音命令变为“您已到达第一个(第二个、第三个等)目的地”。我觉得这很烦人,因为我想要一 strip 有目的地的路线,仅此而已。我只想拥有这一点,所以我有自己的自定义路径,而不是通常由路由应用程序返回的最短路径。我试图通过关闭 voiceInstructions 来避免这个问题,但随后系统变得异常,导航屏幕移动到 lat, lng (0,0),这几乎是非洲西部的某个地方。任何有关我如何解决此问题的帮助都将不胜感激,我很乐意为提供正确答案的人购买一两杯啤酒。我也联系了 Mapbox 支持,但我们还没有找到问题的答案,所以我要求他们在他们的工程团队内部将其升级,我相信,虽然我正在解决的问题并不少见,但它仍然不是经过开发人员的大量测试。干杯!

最佳答案

在 Mapbox Support 和 Rafa Gutierrez 的大力支持下,我来到了这里 我现在可以自己回答这个帖子了。

由于 MapboxMapMatching 自动将 .coordinates 设置为路标,问题已经出现。相反,如果明确编辑航路点变量使其只有两个航路点:起点和目的地,则系统能够处理输入的自定义路线,而无需将每个输入坐标转换为航路点。下面的代码示例有望阐明上述观点:

MapboxMapMatching.builder()
.accessToken(Mapbox.getAccessToken())
.coordinates(lineStringRep.coordinates())
.waypoints(OD)
.steps(true)
.voiceInstructions(true)
.bannerInstructions(true)
.profile(DirectionsCriteria.PROFILE_DRIVING)
.build().enqueueCall(new Callback<MapMatchingResponse>()

其中 OD 是一个整数数组,存储坐标的第一个(起点)和最后一个索引(目的地)

    OD[0] = 0;
OD[1] = features.size() - 1;

关于android - 通过自定义路线进行 Mapbox 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53907414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com