高级地点列表组件
借助“高级地点列表”组件,您可以定义和显示地点列表。您可以列出最多 20 个地点,这些地点来自地点详情组件支持的同一组身份信息(地点 ID、地点资源名称或经纬度坐标)。
您可以选择以水平或垂直列表显示。默认方向为竖屏。每个列表项都提供与紧凑型和完整版地点详情卡片相同的信息和配置选项。
使用 AdvancedPlaceListFragment 的 PlaceActionProvider 接口创建列表。
结算
系统会针对每个列表请求向您收取费用,对列表的任何更改都是新的付费事件。
示例
创建 AdvancedPlaceList fragment
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) } }