android - 我正在尝试通过 Google Places 在 Google Maps 上实现搜索。但是谷歌搜索出现了
问题描述
我正在尝试通过 Google Places 在 Google Maps 上实现搜索。在我的 xml 中,我使用AutoCompleteTextView
元素。但是当我点击search bar
- 谷歌搜索出现为什么?是否可以在没有我的searchbar
情况下实现 google 地方adapter
?
解决方案
来自文档:
要将 AutocompleteSupportFragment 添加到您的应用程序,请执行以下步骤:
- 将片段添加到活动的 XML 布局。
- 为您的活动或片段添加一个侦听器。
布局:
<fragment android:id="@+id/autocomplete_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
/>
代码:
// Initialize the AutocompleteSupportFragment.
val autocompleteFragment =
supportFragmentManager.findFragmentById(R.id.autocomplete_fragment)
as AutocompleteSupportFragment
// Specify the types of place data to return.
autocompleteFragment.setPlaceFields(listOf(Place.Field.ID, Place.Field.NAME))
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(object : PlaceSelectionListener {
override fun onPlaceSelected(place: Place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: ${place.name}, ${place.id}")
}
override fun onError(status: Status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: $status")
}
})
推荐阅读
- android - 协程上下文自定义 getter
- css - 如何在包装在 div 中的 < a > 标签之间留出空格
- vaadin - ExternalResource in Vaadin 10 - Custom Icons for Button
- performance - 多内核性能分析(CUDA C)
- python - 使用 Django 的 CreateView 分配外键
- excel - 有没有办法截断这种水平对齐?
- apache - 使用 .htaccess 和 Apache 进行 301 重定向
- r - 使用 R 中带有 lmer 包的混合效应模型计算弹性
- python - 带有预训练嵌入的 Keras 自动编码器返回错误的维数
- excel - 如何使用 VBA 启用多个 Excel 下拉列表,这些下拉列表输入的值与用户选择的值不同?