PlaceAutocompleteFragment can't resolved

可紊 提交于 2019-12-19 08:52:35

问题


In my app I have added Google Maps and they work fine. I want to add a PlaceAutocompleteFragment. I am using the key which I had already generate for maps and I have enable the option Places Api from google.console. I have added these to my 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'

but when I try to use PlacesAutoCompleteFragment then Android Studio can't resolve this.


回答1:


The problem here is that PlaceAutocompleteFragment didn't exist in version 8.3 of Google Play Services.

This isn't documented very well, but you can see on this blog that PlaceAutocompleteFragment was "announced" in December 2015.

You can also see in the PlaceCompleteFragment Google code samples on GitHub that they are using version 8.4 of GooglePlayServices.

I also had this problem, and updating Google Play Services is what made it work.

So, update Google Play Services in the SDK Manager, and then modify the build.gradle like so, and it should work:

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

Update

In newer versions of Google Play Services, they have broken out the Google Places API, so you need to include it in addition to Maps and 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'


来源:https://stackoverflow.com/questions/34800860/placeautocompletefragment-cant-resolved

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