Advanced Place List コンポーネント

Advanced Place List コンポーネントを使用すると、場所のリストを定義して表示できます。Place Details コンポーネントでサポートされている同じ ID セット(プレイス ID、プレイス リソース名、緯度 / 経度座標)から、最大 20 件の場所を一覧表示できます。

リストは横向きまたは縦向きで表示できます。デフォルトの向きは縦向きです。各リストアイテムには、コンパクトな Place Details カードと完全な Place Details カードと同じ情報と構成オプションを使用できます。

AdvancedPlaceListView の orientation、placeIdentifiers、configuration パラメータを使用してリストを作成します。

課金

リスト リクエストごとに課金され、リストの変更は新しい課金対象イベントになります。

エージェント アプリのトークン

エージェント型データ可視化トークンを使用すると、エージェント型アプリは、Maps Experience Agent Tools(旧称 Maps Grounding Lite)のレスポンスに含まれる場所の Places UI キット 要素を追加料金なしで表示できます。詳細については、エージェント データ可視化トークンをご覧ください。

例

このサンプルでは、場所 ID に基づいてリストを作成します。configuration パラメータは、各リストアイテムに住所、評価、タイプ、その他の視覚的な仕様を表示することを指定します。ユーザーが各リストアイテムをお気に入りに追加またはお気に入りから削除できるように、メイン アクションが作成されます。各リストアイテムのコーナー アクションが無効になっている。

Swift

  struct AdvancedPlaceListDemoView: View {
  private let configuration = AdvancedPlaceListConfiguration(
    content: [.address(), .rating(), .type()],
    preferTruncation: true,
    theme: PlacesMaterialTheme(),
    attributionPosition: .bottom,
    mediaSize = .medium,
    selectable: true
  )
  @State private var placeIdentifiers = [.placeID("ChIJj61dQgK6j4AR4GeTYWZsKWw")]

  @State private var favoritePlaces: Set<String> = []

  var body: some View {
    AdvancedPlaceListView(
      orientation: .horizontal, // default is vertical
      placeIdentifiers: placeIdentifiers,
      configuration: configuration
    )
    .onLoad { results in
      for result in results {
        switch result {
          case .success(let place)
            print("place: \(place)")
          case .failure(let error)
            print("error: \(error)")
        }
      }
    }
    .onPlaceSelected { place, index in
      print("place: \(place)")
      print("index: \(index)")
    }
    .mainActions { place in
      var actions: [MainPlaceActionElement] = []
      let placeID = place.placeID!
      if self.favoritePlaces.contains(placeID) {
        actions.append(
          .action(
            MainPlaceAction(
              image: Image(systemName: "heart.fill"),
              label: "Unfavorite"
            ) { _ in self.toggleFavorite(placeID) }
          )
        )
      } else {
        actions.append(
          .action(
            MainPlaceAction(
              image: Image(systemName: "heart"),
              label: "Favorite"
            ) { _ in self.toggleFavorite(placeID) }
          )
        )
      }
      actions.append(.actionId(.openMap(style: .primary)))
      return actions
    }
    // Ensures that there are no corner actions.
    .cornerActions { _ in
      return []
    }
  }

  func toggleFavorite(_ placeID: String) {
    if favoritePlaces.contains(placeID) {
      favoritePlaces.remove(placeID)
    } else {
      favoritePlaces.insert(placeID)
    }
  }
}