Advanced Place List component

The Advanced Place List component lets you to define and display a list of places. You can list up to 20 places from the same set of identities supported by the Place Details component (Place IDs, Place Resource Names, or lat/long coordinates).

You can choose from a horizontal or vertical list display. The default orientation is vertical. The same information and configuration options as the compact and full place details cards are available for each list item.

Use the orientation, placeIdentifiers, and configuration parameters of AdvancedPlaceListView to create a list. See Example for more details.

Billing

You are billed for each list request, and any change to the list is a new billable event.

Example

This sample creates a list based on place identifiers. The configuration parameter specifies that each list item will list the address, rating, and type, along with other visual specifications. A main action is created to allow a user to favorite or unfavorite each list item. Corner actions are disabled for each list item.

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)
    }
  }
}