“高级地点搜索”组件
“地点搜索”组件的高级版提供与地点搜索基础版相同的功能。您还可以通过该组件配置操作按钮,并对显示的评价和媒体应用搜索和过滤选项。
高级地点搜索配置
使用 AdvancedPlaceSearchFragment 访问高级功能。
配置操作按钮
使用 AdvancedPlaceSearchFragment 的 PlaceActionProvider 接口定义和自定义操作按钮。
视觉必须提供出处要求
重要提示:如果自定义操作按钮会与 Google 以外的第三方分享用户信息,您必须向用户明确说明这一点。请参阅标明出处要求。
该示例显示了一张自定义图片,其中明确指出用户信息将发送到“Altostrat”。
应用搜索和过滤选项
使用 AdvancedPlaceSearchFragment 的 SearchMediaOptions 和 SearchReviewsOptions 接口,可以搜索和过滤媒体或评价。
高级地点搜索示例
创建 AdvancedPlaceSearch fragment
Kotlin
// Initialize Places first Places.initializeWithNewPlacesApiEnabled(context, API_KEY) // How the fragment is created AdvancedPlaceSearchFragment.newInstance( selectedContent, orientation, R.style.BrandedPlaceDetailsTheme, ) // Fragment supports the same configs that PlaceSearchFragment supported fragment.preferTruncation = false fragment.attributionPosition = AttributionPosition.BOTTOM fragment.selectable = true
执行搜索
Kotlin
// Performing a search works the same as with a regular placeSearchFragment. advancedPlaceSearchFragment.configureFromSearchByTextRequest(searchByTextRequest) advancedPlaceSearchFragment.configureFromSearchNearbyRequest(searchNearbyRequest)
聆听结果
Kotlin
// attach the existing PlaceSearchFragmentListener to get notified about 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, its functionally identical but with a new name. is AdvancedPlaceListFragment -> fragment.registerListener(advancedPlaceListFragmentListener) } }