首页 > 解决方案 > 如何创建混合路线,如(行人和汽车)?

问题描述

我有一条包含车辆和行人模式的路线。当 HERE 创建这个时,我想用虚线或不同颜色显示行人部分,以便用户理解。

我像这样解析了 sectionTransportMode 的路线部分

    _routeCalculator.calculatePedestrianRoute(waypoints, (HERE.RoutingError? routingError, List<HERE.Route>? routeList) async {
      if (routingError == null) {
        HERE.Route _calculatedRoute = routeList!.first;

        _calculatedRoute.sections.forEach((element) {
          print('TransportMode: ' + element.sectionTransportMode.toString());

        });

        _showRouteOnMap(_calculatedRoute);
        _startNavigationOnRoute(isSimulated, _calculatedRoute);
      } else {
        final error = routingError.toString();
        _showDialog('Error', 'Error while calculating a pedestrian route: $error');
      }
    });

但是在这个代码片段之后我怎么能做到这一点。

标签: flutterhere-apiheremaps

解决方案


MapPolyline 由三个元素组成:

  1. 定义在地图上放置折线的位置的两个或多个地理坐标的列表。
  2. 包含此坐标列表的 GeoPolyline。
  3. 样式参数,例如DashPatternLineCap,用于定义如何可视化折线。

https://developer.here.com/documentation/android-sdk-navigate/4.8.3.0/dev_guide/topics/map-items.html#add-map-polylines

调用 showRouteOnMap 时,您可以创建带有虚线的 MapPolyline,如下面的示例所示。

这是一个例子:

private void showRouteOnMap(Route route) {
        // Show route as polyline.
        GeoPolyline routeGeoPolyline;
        try {
            routeGeoPolyline = new GeoPolyline(route.getPolyline());
        } catch (InstantiationErrorException e) {
            // It should never happen that a route polyline contains less than two vertices.
            return;
        }

        float widthInPixels = 20;

        //Blue Color
        //Color lineColor = Color.valueOf(0, 0f, 0f, 139f);

        MapPolyline routeMapPolyline = new MapPolyline(routeGeoPolyline,
                widthInPixels,
                Color.valueOf(0, 0.56f, 0.54f, 0.63f)); // RGBA
        //Setting polyline to DashPattern
        routeMapPolyline.setDashPattern(new DashPattern(10));
       // routeMapPolyline.setDashFillColor(lineColor);

        mapView.getMapScene().addMapPolyline(routeMapPolyline);
        mapPolylines.add(routeMapPolyline);

        // Draw a circle to indicate starting point and destination.
        addCircleMapMarker(startGeoCoordinates, R.drawable.green_dot);
        addCircleMapMarker(destinationGeoCoordinates, R.drawable.green_dot);

        // Log maneuver instructions per route section.
        List<Section> sections = route.getSections();
        for (Section section : sections) {
            logManeuverInstructions(section);
        }
    }

请参考 git 中的这个示例: https ://github.com/hermaps/here-sdk-examples/tree/master/examples/latest/navigate/flutter/routing_hybrid_app


推荐阅读