進階地點清單元件

您可以使用「進階地點清單」元件定義及顯示地點清單。您最多可以列出 20 個地點,這些地點必須來自 Place Details 元件支援的同一組 ID (地點 ID、地點資源名稱或經緯度座標)。

你可以選擇水平或垂直顯示清單。預設方向為直向,每個清單項目都提供與精簡和完整地點詳細資料資訊卡相同的資訊和設定選項。

使用 AdvancedPlaceListFragmentPlaceActionProvider 介面建立清單。

帳單

系統會針對每項清單要求收費,清單的任何變更都屬於新的計費事件。

範例

建立 AdvancedPlaceList 片段

Kotlin

// Initialize first
Places.initializeWithNewPlacesApiEnabled(context, API_KEY)

// how fragment is created
AdvancedPlaceListFragment.newInstance(
          selectedContent,
          orientation,
          R.style.BrandedPlaceDetailsTheme,
        )

// fragments support the same configurations that PlaceSearchFragment supports
fragment.preferTruncation = false
fragment.attributionPosition = AttributionPosition.BOTTOM
fragment.mediaSize = AdvancedPlaceListFragment.MediaSize.SMALL
fragment.selectable = true  

顯示地點清單

Kotlin

// You can use resourceNames or placeIds
advancedPlaceListFragment.configureFromPlaceIds(placeIds)

advancedPlaceListFragment.configureFromResourceNames(resourceNames)

// Alternatively, use coordinates, which are a list of LatLng:
advancedPlaceListFragment.configureFromCoordinates(coordinates)
// Uses reverse geocoding to get the place

聆聽結果

Kotlin

// Attach the existing PlaceSearchFragmentListener to get notified when places load or are selected from the results list.
override fun onAttachFragment(fragment: Fragment) {
    super.onAttachFragment(fragment)
    when (fragment) {
      // Reuse the placeSearchFragmetnListener from the Essentials version
      is AdvancedPlaceSearchFragment -> fragment.registerListener(placeSearchFragmentListener)
      // Use placeListFragmentListener, it's functionally identical but with a new name.  
      is AdvancedPlaceListFragment -> fragment.registerListener(advancedPlaceListFragmentListener)
    }
}