首页 > 解决方案 > 最新的 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 的错误

标签: androidkotlingoogle-placesgoogleplacesautocomplete

解决方案


推荐阅读