トラフィックを検索します

専用のを使用 TrafficEngineすると、事故、建設工事、道路閉鎖などの現在の交通事故について、詳細かつローカライズ可能な情報を照会できます。

1 trafficIncidents 行のコードでマップ レイヤー 状態を有効にすることで、地図上の交通事故を視覚化できます。 HERE SDK は trafficFlow 、レイヤーを追加することで現在のトラフィック状況を確認するための別のレイヤーもサポートしています。

また Route、経路 セクションに示されているように、インスタンスに沿ったトラフィックを指定することもできます。

リアルタイムの交通フローとインシデントを地図に表示します

マップ レイヤー状態を有効にする trafficIncidentsと、地図上の交通事故を簡単に視覚化できます。 HERE SDK は、現在のトラフィック状況を確認するための別のレイヤーもサポートしています。 地図上のレイヤーを表示または非表示にする方法については、以下の例を参照してください。

スクリーンショット: 地図上に交通事故が表示されます。

レイヤーを設定すると、地図の表示領域が自動的に更新されます。 そのため、地図をあらゆる方向に自由に移動して、最新の交通事故を確認できます。

多く の状況で、ドライバーは、都市内外での現在の渋滞状況に基づいて最速ルートを探しています。 HERE SDK を使用すると、現在のすべての渋滞を保持しているレイヤーをさまざまな色の線で表示して、渋滞の重大度をリアルタイムで常に更新することができます。 この機能を使用するには、オンライン接続が必要です。また、より多くのデータを消費します。 ただし、交通渋滞ルートは地図のタイルの一部として表示されるため、高性能です。

これらの交通情報は、いくつかのコード行で地図上に表示することも、単独で表示することもできます。

_hereMapController.mapScene.enableFeatures({MapFeatures.trafficFlow: MapFeatureModes.trafficFlowWithFreeFlow});
_hereMapController.mapScene.enableFeatures({MapFeatures.trafficIncidents: MapFeatureModes.defaultMode});

新しいレイヤー状態の設定は同期的に実行されますが、以前にロードしておく必要がある有効なマップ シーン が必要です。 また、新しいマップ シーン の読み込み中に新しいレイヤーの状態を設定すると、例外が発生する可能性があります。 機能レイヤーを非表示にするには、次の番号を呼び出します。

_hereMapController.mapScene.disableFeatures([MapFeatures.trafficFlow, MapFeatures.trafficIncidents]);

トラフィックフローラインは、次のように色分けされています。

  • 緑 : 通常 の交通状況
  • 黄色 / 黄色 : 渋滞しています
  • 赤 : 交通量が非常に多い
  • 黒 : トラフィックのブロック

スクリーンショット: 地図上にインシデントとともに表示される交通量。

GitHub では、 TRAFFIC_APP サンプルアプリの一部として使用例が提供されています。

地図から交通事故を選択します

trafficIncidents にが表示されている場合 MapViewは、タップハンドラを設定し、交通事故を選択して詳細情報を取得できます。

void _setTapGestureHandler() {
  _hereMapController.gestures.tapListener = TapListener((Point2D touchPoint) {
    GeoCoordinates? touchGeoCoords = _hereMapController.viewToGeoCoordinates(touchPoint);
    // Can be null when the map was tilted and the sky was tapped.
    if (touchGeoCoords != null) {
      // Pick incidents that are shown in MapSceneLayers.trafficIncidents.
      _pickTrafficIncident(touchPoint);
    }
  });
}

// Traffic incidents can only be picked, when trafficIncidents is visible.
_pickTrafficIncident(Point2D touchPointInPixels) {
  Point2D originInPixels = new Point2D(touchPointInPixels.x, touchPointInPixels.y);
  Size2D sizeInPixels = new Size2D(1, 1);
  Rectangle2D rectangle = new Rectangle2D(originInPixels, sizeInPixels);

  _hereMapController.pickMapContent(rectangle, (pickMapContentResult) {
    if (pickMapContentResult == null) {
      // An error occurred while performing the pick operation.
      return;
    }

    List<PickTrafficIncidentResult> trafficIncidents = pickMapContentResult.trafficIncidents;
    if (trafficIncidents.length == 0) {
      print("No traffic incident found at picked location");
    } else {
      print("Picked at least one incident.");
      PickTrafficIncidentResult firstIncident = trafficIncidents.first;
      _showDialog("Traffic incident picked:", "Type: " + firstIncident.type.name);

      // Find more details by looking up the ID via TrafficEngine.
      _findIncidentByID(firstIncident.originalId);
    }

    // Optionally, look for more map content like embedded POIs.
  });
}

タップハンドラを使用 mapView.pickMapContent()すると、タッチした位置がビューの座標で取得され、そこに渡すことができます。 HERE では、ポイントサイズの四角形を使用しますが、一度に複数のコンテンツを含めるようにピック領域を拡大することもできます。

コールバック には、 常に地図に表示される、TrafficIncidentResultが含まれているが、デフォルトの POI マーカーなどのその他の埋め込みタイプも含まれているPickMapContentResultがあります。 TrafficIncidentResult このタイプでは、インシデントに関するほとんどの情報がすでに提供されていますが、利用可能なすべての情報を取得するには、を使用 TrafficEngine して(以下のも参照)、 ID で選択したインシデントを検索します。

_findIncidentByID(String originalId) {
  TrafficIncidentLookupOptions trafficIncidentsLookupOptions = new TrafficIncidentLookupOptions();
  // Optionally, specify a language:
  // the language of the country where the incident occurs is used.
  // trafficIncidentsLookupOptions.languageCode = LanguageCode.EN_US;
  _trafficEngine.lookupIncident(originalId, trafficIncidentsLookupOptions,
      (trafficQueryError, trafficIncident) {
    if (trafficQueryError == null) {
      print("Fetched TrafficIncident from lookup request." + " Description: " + trafficIncident!.description.text);
    } else {
      _showDialog("TrafficLookupError:", trafficQueryError.toString());
    }
  });
}

TrafficEngine を使用してインシデントをクエリーします

TrafficEngineは、進行中の交通事故に関する詳細情報を取得できます。 経由、 GeoCorridor経由、または GeoBox 経由でルートに沿ってインシデントを検索 GeoCircleできます。

また、複数のオプションを設定して、特定のタイプのインシデントのみを検索することもできます。 その結果、該当する車両タイプ、日付情報、位置情報、ローカライズ可能な説明、概要などの結果が得られます。

まず、 TrafficEngine次のものの新しいインスタンスを作成します。

try {
  _trafficEngine = TrafficEngine();
} on InstantiationException {
  throw ("Initialization of TrafficEngine failed.");
}

以下では、の内部で GeoCircle 可能性のあるものを検索します TrafficIncidents

void _queryForIncidents(GeoCoordinates centerCoords) {
  double radiusInMeters = 1000;
  GeoCircle geoCircle = GeoCircle(centerCoords, radiusInMeters);
  TrafficIncidentsQueryOptions trafficIncidentsQueryOptions = TrafficIncidentsQueryOptions();
  // Optionally, specify a language:
  // the language of the country where the incident occurs is used.
  // trafficIncidentsQueryOptions.languageCode = LanguageCode.enUs;
  _trafficEngine.queryForIncidentsInCircle(geoCircle, trafficIncidentsQueryOptions,
      (TrafficQueryError? trafficQueryError, List<TrafficIncident>? trafficIncidentsList) {
    if (trafficQueryError != null) {
      _showDialog("TrafficQueryError", "Error: " + trafficQueryError.toString());
      return;
    }

    // If error is null, list is guaranteed to be not empty.
    String trafficMessage = "Found ${trafficIncidentsList!.length} result(s). See log for details.";
    TrafficIncident? nearestIncident = _getNearestTrafficIncident(centerCoords, trafficIncidentsList);
    if (nearestIncident != null) {
      trafficMessage += " Nearest incident: " + nearestIncident.description.text;
    }
    _showDialog("Nearby traffic incidents", trafficMessage);

    for (TrafficIncident trafficIncident in trafficIncidentsList) {
      print(trafficIncident.description.text);
    }
  });
}

見つかった各 TrafficIncident項目について、その説明を記録します。 ドイツで検索する場合、デフォルトではドイツ語で結果が表示されます。 次のように表示されます。

Berlin, Sachsendamm zwischen Gotenstraße und Priesterweg Fahrbahn auf einen Fahrstreifen verengt, Staugefahr, Bauarbeiten, bis voraussichtlich 20.02.2028

別の言語を指定することもできます。たとえば、次のように設定します。

trafficIncidentsQueryOptions.languageCode = LanguageCode.enUs;

MapSceneLayers.trafficIncidents は、お問い合わせの場所を示すためにトラフィックのアイコンと行をレンダリングするレイヤーです。

TrafficIncident には GeoPolyline 、その場所を示すが含まれています。 地図上のタップした場所とポリライン に含まれている地理座標を比較することで、地図上のタップした場所に最も近いインシデントを見つけることができます。

TrafficIncident? _getNearestTrafficIncident(
    GeoCoordinates currentGeoCoords, List<TrafficIncident> trafficIncidentsList) {
  if (trafficIncidentsList.length == 0) {
    return null;
  }

  // By default, traffic incidents results are not sorted by distance.
  double nearestDistance = double.maxFinite;
  TrafficIncident? nearestTrafficIncident;
  for (TrafficIncident trafficIncident in trafficIncidentsList) {
    // In case lengthInMeters == 0 then the polyline consistes of two equal coordinates.
    // It is guaranteed that each incident has a valid polyline.
    for (GeoCoordinates geoCoords in trafficIncident.location.polyline.vertices) {
      double currentDistance = currentGeoCoords.distanceTo(geoCoords);
      if (currentDistance < nearestDistance) {
        nearestDistance = currentDistance;
        nearestTrafficIncident = trafficIncident;
      }
    }
  }

  return nearestTrafficIncident;
}

もちろん、を追加する MapPolylineことで、自分自身でインシデントのポリライン をマップに表示することもできます。 MapMarker インシデントのタイプに応じて、別のイメージを選択するように独自のアイコンを追加することもできます。

ラジオ局から交通ブロードキャストを取得します

TrafficDataProvider インターフェイスを使用すると、 HERE SDK は交通放送を提供するラジオ局の信号を統合できます。

TrafficBroadcastRDS-TMC 形式を想定しており OfflineRoutingEngine 、インターネットに接続されていない場合に使用できます。これにより、はラジオチャネル経由で送信される交通データを利用できます。

trafficBroadcast.activate() トラフィックデータイベントを受信するには、メソッドを呼び出す必要があります。

TrafficBroadcast 、位置情報ソースから提供された新しい位置に継続的に反応 LocationListenerし、として機能します。 電話の種類にかかわら activate()ず、位置情報を更新する必要があります。

インターフェイスを採用するには、特別なハードウェアが必要です。 詳細については、 HERE の担当者にお問い合わせください。 これはベータ版の機能としてリリースされています。

」に一致する結果は 件です

    」に一致する結果はありません