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