4

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.

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
user4292106
  • 441
  • 1
  • 11
  • 24

1 Answers1

8

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'
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • ok! now I am updating the sdk manager. Can i remove the play-servises:8.0.4? If I keep only the play-services-maps and play-services-location will be ok? – user4292106 Jan 14 '16 at 23:16
  • @user4292106 Yes, it should be ok. The last line was including all of Google Play Services, which is not needed. – Daniel Nugent Jan 14 '16 at 23:52
  • ok thanks! After a couple oh hours android studio finished with update! – user4292106 Jan 15 '16 at 05:44
  • i have one more question. I have implement the placeAutoCompleteFragment and it works fine. I am getting placeName and placeLatLng. When I get the placeLatLng I want to add a marker in map in same activity which implements the OnMapReadyCallback. I have try to add the listener for placeAutoCompleteFragment inside of onMapReady but it doesn't work. When I have the listener inside of the onCreate then the map isn't ready. – user4292106 Jan 15 '16 at 07:28
  • @user4292106 autocomplete in map get disappear all of the sudden – Arnold Brown Jul 13 '19 at 12:30