在我的应用程序中,我添加了 Google map ,它们运行良好。我想添加一个 PlaceAutocompleteFragment。我正在使用我已经为 map 生成的 key ,并且我已经从 google.console 启用了 Places Api 选项。我已将这些添加到我的 build.gradle 中:

compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'com.google.android.gms:play-services:8.3.0'

但是当我尝试使用 PlacesAutoCompleteFragment 时,Android Studio 无法解决这个问题。

最佳答案

这里的问题是 PlaceAutocompleteFragment 在 Google Play 服务的 8.3 版中不存在。

这没有很好的记录,但是您可以在 this blog 上看到 PlaceAutocompleteFragment 于 2015 年 12 月“公布”。

您还可以看到 in the PlaceCompleteFragment Google code samples on GitHub 他们正在使用 8.4 版的 GooglePlayServices。

我也遇到了这个问题,更新 Google Play 服务是让它起作用的原因。

因此,在 SDK Manager 中更新 Google Play Services,然后像这样修改 build.gradle,它应该可以工作:

compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'

更新

在较新版本的 Google Play 服务中,他们打破了 Google Places API,因此除了 Maps 和 Location 之外,您还需要包含它:
compile 'com.google.android.gms:play-services-maps:11.0.2'
compile 'com.google.android.gms:play-services-location:11.0.2'
compile 'com.google.android.gms:play-services-places:11.0.2'

10-07 19:26
查看更多