Places API autocomplete problems

为君一笑 提交于 2021-01-28 19:31:31

问题


Hi I'm new to android and am setting up the autocomplete code for the places api. I was following the google dev instructions on their website and ran into a problem that I can't seem to find any answers on.

I can't seem to find any info on what i am supposed to put for ID and NAME on the first line. There are no auto complete suggestions that come up and I haven't been able to find any info on it on the official documentation. I believe I have imported everything that I need to as I don't have any errors anywhere else in the code.

This is the guide I am following. I am in the section to add the autocomplete by using an intent. https://developers.google.com/places/android-sdk/autocomplete

val location = findViewById<View>(R.id.location_button)
    location.setOnClickListener {
        val fields = listOf(Place.TYPE_RESTAURANT.ID,Place.TYPE_RESTAURANT.NAME)
        val intent = Autocomplete.IntentBuilder(
            AutocompleteActivityMode.OVERLAY, fields).build(this)
        startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE)

回答1:


You need to use Place.Field as documented here. Like this:

val fields = listOf(Place.Field.ID,Place.Field.NAME)

Hope this helps!



来源:https://stackoverflow.com/questions/60748705/places-api-autocomplete-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!