最新的Google Places API是否有错误?

时间:2019-05-13 09:53:49

标签: android kotlin google-places googleplacesautocomplete

我目前正在将Google地方自动填充功能添加到我的项目中。该文件说,我们应该使用最新的Google Places API并使用其他库。我已经正确地遵循了文档的教程。我在AppCompatActivity上使用自动完成覆盖模式。绝对可以,但是我发现了一些错误。首先,当我输入一个完全叫“ Bali”的地名时,它显示一个空列表,但是当我键入“ 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的错误

0 个答案:

没有答案