android - 最新的 google places api 有错误吗?
问题描述
我目前正在将 google 地方自动完成添加到我的项目中。该文档说我们应该使用最新的 google places API 并使用不同的库。我已经正确地遵循了文档的教程。我在 AppCompatActivity 上使用自动完成覆盖模式。它肯定有效,但我发现了一些错误。首先,当我输入一个完全可以说“巴厘岛”的地名时,它会显示一个空列表,但是当我输入“Ba”时,它会显示一个包含名称“Ba”的地点列表。其次,在我点击建议列表后,片段不会关闭并继续搜索相同名称的地点。
我尝试使用不同的方式。我试图使用意图和东西。它也可以工作,但显示相同的错误。
这是我一直在处理的代码:
if (!Places.isInitialized()) { Places.initialize(applicationContext, resources.getString(R.string.google_maps_key)) }
placesClient = Places.createClient(this)
autocompleteSupportFragment = supportFragmentManager.findFragmentById(R.id.autocomplete_fragment) as AutocompleteSupportFragment?
autocompleteSupportFragment?.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME))
autocompleteSupportFragment?.setLocationBias(RectangularBounds.newInstance(LAT_LNG_BOUNDS))
autocompleteSupportFragment?.setOnPlaceSelectedListener(object : PlaceSelectionListener {
override fun onPlaceSelected(place: Place) {
mGoogleMap!!.addMarker(MarkerOptions().position(place.latLng!!).title(place.name.toString()))
mGoogleMap?.animateCamera(CameraUpdateFactory.newLatLngZoom(place.latLng, 14f))
}
override fun onError(status: Status) {
}
})
我希望当我单击结果时,片段将关闭并设置片段的文本。但是片段并没有关闭并且总是不断地搜索同一个地方。对我如何正确使用此 API 有什么建议吗?因为这似乎是这个 API 的错误
解决方案
推荐阅读
- javascript - 使 html 页面的某些部分不可滚动且不可见
- reactjs - firebase facebook弹出窗口太大
- c# - Unity:更新功能期间的触摸控制
- python - Python selenium driver instance not defined even though instance is returned by method
- python - Django 从文本字段中的 JSON 字符串中检索 JSON 键/值
- python - Python if 和 isinstance 在这个例子中是如何工作的?
- c++ - 降序插入排序
- python - 我有一个要下载的 .mp4 文件的链接。但在我下载它之前,我希望它被压缩。有什么建议吗?
- node.js - 如何使用 json2csv 创建文件并将其上传到 Firebase 存储
- scala - 以日期为键在 Seq 上滚动总和