【问题标题】:Places API autocomplete problemsPlaces API 自动完成问题
【发布时间】:2020-06-30 02:06:43
【问题描述】:

您好,我是 android 新手,正在为 places api 设置自动完成代码。我按照他们网站上的 google 开发说明进行操作,遇到了一个我似乎找不到任何答案的问题。

我似乎找不到任何关于我应该在第一行为 ID 和 NAME 输入什么的信息。没有出现自动完成建议,我也无法在官方文档中找到任何相关信息。我相信我已经导入了我需要的所有内容,因为我在代码的其他任何地方都没有任何错误。

这是我正在遵循的指南。我在使用意图添加自动完成的部分。 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)

【问题讨论】:

  • 您的代码看起来不错,未显示结果的可能原因是 API 密钥使用错误,或者您可能没有在谷歌控制台中为所选项目/API 密钥激活 Places API。跨度>
  • 当您单击该 location_button 时,logcat 会说什么?

标签: android android-studio google-maps kotlin google-places-api


【解决方案1】:

您需要使用Place.Field,如记录的here。像这样:

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

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 2020-08-12
    • 2013-10-10
    • 1970-01-01
    • 2017-04-22
    • 2014-05-01
    • 2017-10-02
    • 1970-01-01
    • 2022-06-19
    • 2023-01-31
    相关资源
    最近更新 更多