GuidesFlutter API ReferencesHERE SDK for Android API referencesHERE SDK for iOS API references
Guides

Access map data on-the-fly

SegmentDataLoader is only available with the Navigate license.

In order to access and retrieve map segment data, you can use the SegmentDataLoader. It provides an interface for accessing map data available in the OCM map such as speed limits and road attributes.

The SegmentDataLoader first checks if data was prefetched (cached) and if not available, it attempts to download it from the remote server. The operations are synchronous and will block the thread from which they are called. If called from the main thread, it will block the main thread. For best performance, it is recommended to call these methods from a background thread or to prefetch the map data around your working area.

By calling getSegmentsAroundCoordinates(), you can obtain a list of OCMSegmentId objects representing segments near the specified location. Once retrieved, these IDs can be used to load detailed segment data, including structural and regulatory attributes such as PhysicalAttributes of a road and SegmentSpeedLimit.

For optimal results when working with location-based segment queries, consider using map-matched coordinates rather than raw GPS coordinates. The MapMatcher can align your location signals to the road network, ensuring you retrieve segment data for the correct road position. The MapMatcher already provides some segment information, but if you need the full segment data, you can use the map-matched coordinates with the SegmentDataLoader. See Map matching locations for details on improving location accuracy before querying segment data.

void loadAndProcessSegmentData() {
    if (_startGeoCoordinates == null) {
      _showDialog("SegmentData", "You need to add the route before loading the segment data.");
      return;
    }

    _showDialog("SegmentData", "Loading attributes of a map segment. Check logs for details.");

    double radiusInMeters = 500;

    // The necessary SegmentDataLoaderOptions need to be turned on in order to find the requested information.
    // It is recommended to turn on only the data you are interested in by setting the corresponding fields to true.
    SegmentDataLoaderOptions options = SegmentDataLoaderOptions();

    options.loadBaseSpeeds = true;
    options.loadRoadAttributes = true;

    try {
      // Fetch segment IDs around the starting coordinates
      List<OCMSegmentId> segmentIds = _segmentDataLoader.getSegmentsAroundCoordinates(_startGeoCoordinates!, radiusInMeters);

      for (OCMSegmentId segmentId in segmentIds) {
        SegmentData segmentData = _segmentDataLoader.loadData(segmentId, options);

        List<SegmentSpanData> segmentSpanDataList = segmentData.spans;
        if (segmentSpanDataList.isEmpty) {
          debugPrint("SegmentSpanDataList is empty.");
          continue;
        }

        for (SegmentSpanData span in segmentSpanDataList) {
          debugPrint("Physical attributes of ${span.toString()} span.");
          debugPrint("Private roads: ${span.physicalAttributes?.isPrivate}");
          debugPrint("Dirt roads: ${span.physicalAttributes?.isDirtRoad}");
          debugPrint("Bridge: ${span.physicalAttributes?.isBridge}");
          debugPrint("Tollway: ${span.roadUsages?.isTollway}");
          debugPrint("Average expected speed: ${span.positiveDirectionBaseSpeedInMetersPerSecond}");
        }
      }
    } catch (e) {
      debugPrint("Error loading segment data: $e");
    }
}

You can find an example implementation for this in the "routing_with_avoidance_options_app" example app on GitHub.