ルート トークン

ライドシェアリングの最適ルートを決定する際に、最速ルートが必ずしも最適な選択肢になるとは限りません。ルートをカスタマイズすることもできます。Routes Preferred API では、ComputeCustomRoutes メソッドを使用してルートの目標を指定することで、ルートをカスタマイズできます。

カスタムルートを作成すると、Routes Preferred API によってルートトークンが生成されます。その後、トークンを Navigation SDK for Android に渡して、カスタムルートを取得できます。

カスタムルートの作成の詳細については、カスタムルートの作成をご覧ください。

カスタムルートの取得

カスタムルートを取得するには、Navigator.setDestinations メソッドを使用してルートトークンを Navigation SDK for Android に渡します。

setDestinations(List<Waypoint> destinations, CustomRoutesOptions customRoutesOptions, DisplayOptions displayOptions);

カスタムルートは、以前に設定された宛先をオーバーライドします。対応するドライバーの開始場所、道路状況、交通状況が使用されます。

Navigator.setDestinations は次のパラメータを取ります。

パラメータ説明
宛先 設定する新しい宛先リスト。
customRoutesOptions Routes Preferred API から返されたトークンに基づいて、事前に計算されたルートを取得するために使用されるオプション。
displayOptions 経路の表示に使用されるオプション。

Navigator.setDestinations メソッドはリクエストのステータスを返します。ユーザーの現在地から指定された目的地へのルートが見つかった場合は、RouteStatus.OK を返します。

次のコード例は、カスタムルートを取得する方法を示しています。

ArrayList <Waypoint> destinations = Lists.newArrayList();
Waypoint waypoint1 =
   Waypoint.builder()
      .setLatLng(10, 20)
      .setTitle("title")
      .setVehicleStopover(true)
      .build();
destinations.add(waypoint1);
Waypoint waypoint2 =
   Waypoint.builder()
      .setPlaceId("ChIJYV-J-ziuEmsRIMyoFaMedU4")
      .setTitle("title")
      .setVehicleStopover(true)
       .build()
destinations.add(waypoint2);

String routeToken = "route token returned by RoutesPreferred API";

CustomRoutesOptions customRoutesOptions =
   CustomRoutesOptions.builder()
      .setRouteToken(routeToken)
      .setTravelMode(CustomRoutesOptions.TravelMode.TWO_WHEELER)
      .build();

// Existing flow to get a Navigator.
NavigationApi.getNavigator(...);
// Existing flow for requesting routes.
ListenableResultFuture<RouteStatus> routeStatusFuture =
          navigator.setDestinations(destinations, customRoutesOptions);

// Or with display options.
DisplayOptions displayOptions = new DisplayOptions();

ListenableResultFuture<RouteStatus> routeStatusFuture =
          navigator.setDestinations(destinations, customRoutesOptions, displayOptions);