高级地点搜索组件
高级版“地点搜索”组件提供的功能与地点搜索基础版相同。您还可以配置该组件的操作按钮,并对显示的评价和媒体应用搜索和过滤选项。
高级地点搜索配置
使用 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) } }