有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在地图上获取路线点

我正在使用mapboxapi,希望通过List<Point>获得从AB的方向,我可以使用它在地图上绘制正确的路径。但问题是DirectionsResponse返回的点数不够,请参阅

enter image description here

管线的一部分位于水面上。 可能在MapboxDirections类中,或者另一个类中有step方法和meters参数,以每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());
            }
        }

共 (1) 个答案

  1. # 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();