高级地点列表组件
借助高级地点列表组件,您可以定义和显示地点列表。您可以列出最多 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) } }