使用 Google Place API 自动完成 TextView

Posted

技术标签:

【中文标题】使用 Google Place API 自动完成 TextView【英文标题】:Autocomplete TextView using Google Place API 【发布时间】:2015-07-28 09:03:46 【问题描述】:

尝试使用 Google Place API 开发 android AutoComplete TextView,当我在浏览器中尝试我的编码 URL 时遇到一个奇怪的错误。

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=mar&types=geocode&sensor=false&key=BROWSER_KEY

"error_message" : "此 API 项目无权使用此 API。请确保在 API 控制台中激活此 API:了解更多:https://code.google.com/apis/console", “预测”:[], “状态”:“REQUEST_DENIED”

我尝试了网络上几乎所有可能的解决方案,并在我的谷歌开发者控制台中检查 Google Place API 是否已启用。

请有人在这方面帮助我。

提前致谢。

【问题讨论】:

【参考方案1】:

您必须将 URL 中的 BROWSER_KEY 替换为在开发者控制台中创建的实际密钥。

见:https://developers.google.com/places/webservice/intro#Authentication

此外,您可以通过 Google Play 服务访问 Google Places API。无需在 Android 上使用 web 服务。 (https://developers.google.com/places/android/start)

【讨论】:

我认识那个塞巴斯蒂安。我已经用实际密钥替换了它,并尝试使用 android id、服务器 id 和浏览器 id。 如果你想使用Webapi你必须使用API key作为BROWSWER_KEY。转到您的开发者控制台,选择您的项目,APIs & AuthCredentialPublic API accessCreate new Key。假设您激活了Google Places API Web Service。这对我有用。 感谢塞巴斯蒂安的快速评论。我需要激活 Google Places API 网络服务,但这不是免费的并且有定价。在注册时我还需要输入公司名称和域名,所以如果我启用 Android 的 Google Place API 并生成浏览器密钥,那么它是否有效。 您每天可以免费进行 1000 个请求。 developers.google.com/places/webservice/usage 你好塞巴斯蒂安请看截图dropbox.com/s/2wpvjbrdr82rcde/…

以上是关于使用 Google Place API 自动完成 TextView的主要内容,如果未能解决你的问题,请参考以下文章

当我尝试将 google place 自动完成 API 与 Axios 一起使用时出现 CORS 错误

如何在工具栏中实现自动完成 google place api - Android

Google Places API,使用邮政编码自动完成

Google Places API 网络服务:如何为自动完成设置多种类型

Google 地图自动填充的“place_changed”以外的事件

Google Places web api 不与 superagent 合作