【问题标题】:Mapbox Navigation SDK, problem adding waypoints to a NavigationRoute.builder()Mapbox Navigation SDK,向 NavigationRoute.builder() 添加航点的问题
【发布时间】:2019-03-08 02:31:41
【问题描述】:

目前我正在尝试在 mapbox 提供的 android 导航 SDK 中创建导航路线。当向查询中添加多个航点时,问题就开始了。 (下面的查询返回响应并在地图上绘制路线)

NavigationRoute.builder()
            .accessToken(Mapbox.getAccessToken())
            .origin(start)
            .destination(end)
            .alternatives(false)
            .build()
            .getRoute(new Callback<DirectionsResponse>() {
                @Override
                public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) {

                    if (response.isSuccessful()) {

                        try {
                            assert response.body() != null;
                            routeodfgoh = response.body().routes().get(0);

                            if (navigationMapRoute != null) {
                                navigationMapRoute.removeRoute();
                            } else {
                                navigationMapRoute = new NavigationMapRoute(null, mapView, map);
                            }

                            //how to draw the map think map matching is work
                            navigationMapRoute.addRoute(routeodfgoh);

                        } catch (Exception ex) {
                            Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_LONG);
                        }

                    }
                }

                @Override
                public void onFailure(Call<DirectionsResponse> call, Throwable t) {

                }
            });

但是,应用程序要求某些查询添加多个航点。经过大量搜索后,我发现了这个mapbox-navigation-android add waypoints,它导致了下面的代码。但是,查询永远不会返回响应。

 NavigationRoute.Builder builder = NavigationRoute.builder()
            .accessToken(Mapbox.getAccessToken())
            .origin(start)
            .destination(end);

    for (Point waypoint : coords) {
        builder.addWaypoint(waypoint);
    }

    builder.build()
            .getRoute(new Callback<DirectionsResponse>() {
        @Override
        public void onResponse(@NonNull Call<DirectionsResponse> call, @NonNull Response<DirectionsResponse> response) {

           if (response.isSuccessful()) {

                try {
                    assert response.body() != null;
                    routeodfgoh = response.body().routes().get(0);

                    if (navigationMapRoute != null) {
                        navigationMapRoute.removeRoute();
                    } else {
                        navigationMapRoute = new NavigationMapRoute(null, mapView, map);
                    }

                    //how to draw the map think map matching is work
                    navigationMapRoute.addRoute(routeodfgoh);

                } catch (Exception ex) {
                    Toast.makeText(MainActivity.this, ex.toString(), Toast.LENGTH_LONG);
                }

            }
        }

        @Override
        public void onFailure(Call<DirectionsResponse> call, Throwable t) {

        }
    });

任何关于为什么我没有得到回应的想法都会很棒。

【问题讨论】:

    标签: android mapbox mapbox-android


    【解决方案1】:

    默认配置文件是PROFILE_DRIVING_TRAFFIC,其坐标限制为 3 个。如果您将其更新为PROFILE_DRIVING,使用.profile(DirectionsCriteria.PROFILE_DRIVING),应该可以解决坐标限制问题。

    【讨论】:

    • throwable 显示我添加了太多坐标,根据 throwable 允许的最大值为 3。它说的文档允许添加多达 25 个航点,包括起点和终点。我是否错误地使用了这个类?如果是这样,我需要做什么来创建具有 25 个航点的导航路线?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 2021-01-03
    相关资源
    最近更新 更多