PlaceAutocompleteFragment无法解决

use*_*106 4 android google-places-api

在我的应用中,我添加了Google地图,它们运行正常.我想添加一个PlaceAutocompleteFragment.我正在使用我已经为地图生成的密钥,我已经启用了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'
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用PlacesAutoCompleteFragment时,Android Studio无法解决此问题.

Dan*_*ent 8

这里的问题是PlaceAutocompleteFragmentGoogle Play服务版本8.3中不存在.

这没有很好的记录,但你可以在2015年12月"宣布"的博客上看到PlaceAutocompleteFragment.

您还可以在GitHub上的PlaceCompleteFragment Google代码示例中看到他们正在使用GooglePlayServices的8.4版本.

我也有这个问题,更新Google Play服务是它的工作原理.

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

compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
Run Code Online (Sandbox Code Playgroud)

更新

在较新版本的Google Play服务中,他们已经打破了Google Places API,因此除了地图和位置之外,您还需要添加它:

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'
Run Code Online (Sandbox Code Playgroud)