【问题标题】:Get route points on the map获取地图上的路线点
【发布时间】:2019-06-21 11:57:51
【问题描述】:

我正在使用 ma​​pbox API 并希望使用 List<Point> 获取从 AB 的方向,我可以使用它来正确绘制地图上的路径。但问题是DirectionsResponse返回的积分不够,见

线的一部分位于水面上。 可能在MapboxDirections 类或另一个类中具有带有meters 参数的step 方法,每10m 获取Point

这是我当前的代码:

MapboxDirections directions = MapboxDirections.builder()
                .accessToken(ACCESS_TOKEN)
                .profile(PROFILE_DRIVING)
                // Brooklyn, NY, USA
                .origin(Point.fromLngLat(-73.947803, 40.677790))
                // Upper West Side, NY, USA
                .destination(Point.fromLngLat(-73.971609, 40.784246))
                .build();

        Response<DirectionsResponse> response = directions.executeCall();
        DirectionsResponse directionsResponse = response.body();
        for (DirectionsRoute route : directionsResponse.routes()) {
            List<Point> decode = PolylineUtils.decode(route.geometry(), PRECISION_6);
            // I need here more points
            for (Point point : decode) {
                System.out.println(point.latitude() + ", " + point.longitude());
            }
        }

【问题讨论】:

  • 我通过使用RouteLegsteps(true)MapboxDirections 找到了一些解决方案,但是代码看起来有点糟糕,有很多圈子

标签: java navigation mapbox


【解决方案1】:

尝试添加.overview(DirectionsCriteria.OVERVIEW_FULL)获得所有积分like in this example

您的代码将如下所示:

MapboxDirections directions = MapboxDirections.builder()
                .accessToken(ACCESS_TOKEN)
                .profile(PROFILE_DRIVING)
                .overview(DirectionsCriteria.OVERVIEW_FULL) /** New line **/
                // Brooklyn, NY, USA
                .origin(Point.fromLngLat(-73.947803, 40.677790))
                // Upper West Side, NY, USA
                .destination(Point.fromLngLat(-73.971609, 40.784246))
                .build();

【讨论】:

    猜你喜欢
    • 2015-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2010-11-03
    • 2017-05-12
    相关资源
    最近更新 更多