23

I am trying to implement a autocomplete places search following this article.

http://www.truiton.com/2015/04/android-places-api-autocomplete-getplacebyid/

I have followed all steps, and also added proper dependencies in my build.gradle file.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}

Also here are the meta data section in my manifest.

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

also I have all the required SDK components installed. Still my android studio can not resolve the places part in the following imports:

import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.AutocompletePrediction;
import com.google.android.gms.location.places.AutocompletePredictionBuffer;
import com.google.android.gms.location.places.Places;

this is how they look as they can not find the Places part.

enter image description here

How can I resolve this issue? I am using SDK 19 for my app.

Bluemarble
  • 1,925
  • 4
  • 20
  • 35

9 Answers9

49

Add compile 'com.google.android.gms:play-services-places:<version>, where <version> is perhaps at least: 9.2.1 under dependencies in your modules's build.gradle

Ujjwal Singh
  • 4,908
  • 4
  • 37
  • 54
26

In play-services 9.2.0 the places API is no longer located in location. Those are now in their own places dependency. To resolve those you should add this to your build.gradle.

compile 'com.google.android.gms:play-services-places:9.2.0'

check out

Places class is removed from android play services 9.2.0

vishwajit76
  • 2,300
  • 20
  • 16
14

The Places API was only added in Google Play services 7.0: you'll need to update your dependency to be at least 7.0.0, although the latest as of this answer is 15.0.0.

Note in almost every case, you should use selective APIs to only include the portions of Google Play services you need. In that case, you'd actually use a dependency such as

implementation 'com.google.android.gms:play-services-location:15.0.0'
Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • My issue is that given that it is adviced not to mix playservice versions, i still can't resolve the PlacesAutocomplete component with the latest version of the google play service (8.3.0). I need some assistance @ianhanniballake – Akah Feb 20 '16 at 18:54
  • @larrytech - I'd suggest looking through the [connecting to the Places API guide](https://developers.google.com/places/android-api/start#connect-client) and the [autocomplete guide](https://developers.google.com/places/android-api/autocomplete) and asking a separate question with your code and where you are running into an issue with adding auto-complete. – ianhanniballake Feb 20 '16 at 23:04
  • 1
    i am trying to use this code inorder to create an intent that will call the placeautomplete action, Intent interestintent =new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN) .build(this); This doesn't work as the PlaceAutocomplete class fails to resolve. Like i said, am using the latest version of playservices version 8.3.0 and this code is gotten from the 'connecting to the places API guide'. – Akah Feb 23 '16 at 20:45
  • @larrytech I have same as this problem and my play-services:8.3.0 couldn't resolve com.google.android.gms.location.places.ui.PlaceAutocomplete ,how can I solve it? – Saeed Hashemi Jun 07 '16 at 12:38
  • @SaeedHashemi - make sure to check out the [latest developer guide for Places Autocomplete](https://developers.google.com/places/android-api/autocomplete) - things have changed. – ianhanniballake Jun 07 '16 at 16:49
  • @ianhanniballake what exactly has changed? – Zapnologica Jul 08 '16 at 05:43
  • @AnandSavjani - if you have a better answer, please do add it. For people using the less than 7.0.0 dependency, this is indeed the correct answer – ianhanniballake Sep 14 '16 at 06:22
8

Since Play Services version 9.2 we should add the following dependancy to access Google Places API.

 compile 'com.google.android.gms:play-services-places:11.0.2'

The latest version at the time of this writing.

The accepted answer for this thread was outdated.

Yuvi
  • 419
  • 7
  • 12
7

Add following two dependencies in your build.gradle(Module: app)

implementation  'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
Jenis Kasundra
  • 583
  • 9
  • 19
5

try including compile 'com.google.android.gms:play-services-places:10.2.0'

Alaeddine Zidi
  • 556
  • 5
  • 6
0

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

Just add it in your dependency (build.gradle [Module:Application]) Then file -> Invalidate caches/restart-> invalidate and Restart

sabari vasagan
  • 404
  • 5
  • 18
0

For latest versions of google play services for location changes have been made. Check [Selective Google Play Services API not finding classes

Ron AB
  • 80
  • 7
0

I was also faced with the same issue recently and adding this

implementation 'com.google.android.gms:play-services-places:11.4.0'

to my dependency under build.gradle(app) file solves the problem for me.

NB: make sure the version of your dependencies are all thesame if not you will encounter or errors

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33