配達車両の場所を更新する

Approaches

Fleet Engine で最高のパフォーマンスを得るには、車両の流れを提供します 位置情報は少なくとも 1 分に 1 回、最大で 5 秒に 1 回更新されます。 これらの更新を提供するには、次のいずれかの方法を使用します。

  • Driver SDK を使用する: 最もシンプルなオプション。
  • カスタムコードを使用する: ロケーションがバックエンド経由でリレーされる場合に便利です。 Android または iOS 以外のデバイスを ご使用の場合ですこのドキュメントでは、 アプローチです

車両の位置情報の更新を提供する方法にかかわらず、バックエンドは Fleet Engine は、配達車両が目的地に配送中の場合に、 停車地に到着したときなどですこれにはデポ自体も含まれます。フリート エンジン 自動的には検出されません。

車両位置情報の更新の例

Java gRPC ライブラリを使用して、フリート内の車両の位置を更新できます。 REST を使用する方法もあります。

Java

  static final String PROJECT_ID = "my-delivery-co-gcp-project";
  static final String VEHICLE_ID = "vehicle-8241890";

  DeliveryServiceBlockingStub deliveryService =
    DeliveryServiceGrpc.newBlockingStub(channel);

  // Vehicle settings
  String vehicleName = "providers/" + PROJECT_ID + "/deliveryVehicles/" + VEHICLE_ID;
  DeliveryVehicle myDeliveryVehicle = DeliveryVehicle.newBuilder()
      .setLastLocation(DeliveryVehicleLocation.newBuilder()
          .setSupplementalLocation(LatLng.newBuilder()
              .setLatitude(37.3382)
              .setLongitude(121.8863))
          .setSupplementalLocationTime(now())
          .setSupplementalLocationSensor(DeliveryVehicleLocationSensor.CUSTOMER_SUPPLIED_LOCATION)
          .setSupplementalLocationAccuracy(DoubleValue.of(15.0)))  // Optional
      .build();

  // DeliveryVehicle request
  UpdateDeliveryVehicleRequest updateDeliveryVehicleRequest =
    UpdateDeliveryVehicleRequest.newBuilder()  // No need for the header
        .setName(vehicleName)
        .setDeliveryVehicle(myDeliveryVehicle)
        .setUpdateMask(FieldMask.newBuilder()
            .addPaths("last_location"))
        .build();

  try {
    DeliveryVehicle updatedDeliveryVehicle =
        deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);
  } catch (StatusRuntimeException e) {
    Status s = e.getStatus();
    switch (s.getCode()) {
       case NOT_FOUND:
         break;
       case PERMISSION_DENIED:
         break;
    }
    return;
  }

REST

PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<id>?updateMask=last_location

リクエストの詳細

リクエストの本文には、次の項目を指定する DeliveryVehicle エンティティを含める必要があります。 次のように指定します。

  • 必須フィールド:

    フィールド
    lastLocation.supplementalLocation 車両の位置。
    lastLocation.supplementalLocationTime 車両がこの場所にいたことが最後に判明したタイムスタンプ。
    lastLocation.supplementalLocationSensor CUSTOMER_SUPPLIED_LOCATION を入力する必要があります。

  • オプション フィールド:

    フィールド
    lastLocation.supplementalLocationAccuracy 指定した場所の精度(メートル単位)。

  # Set JWT, PROJECT_ID, VEHICLE_ID, TASK1_ID, and TASK2_ID in the local
  # environment
  curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}?updateMask=remainingVehicleJourneySegments" \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer ${JWT}" \
    --data-binary @- << EOM
  {
    "lastLocation": {
      "supplementalLocation": {"latitude": 12.1, "longitude": 14.5},
      "supplementalLocationTime": "$(date -u --iso-8601=seconds)",
      "supplementalLocationSensor": "CUSTOMER_SUPPLIED_LOCATION",
      "supplementalLocationAccuracy": 15
    }
  }
  EOM

次のステップ