33

I have download a demo project from http://developer.android.com/training/location/retrieve-current.html, and I think I don't lost any steps; But I can't find which jar file contain the “com.google.android.gms.location.LocationClient.class” file

We found all "google-play-services.jar" and "maps.jar", and "android.jar (All versions)" don't contain the "LocationClient.class"?

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
Jerry Sun
  • 331
  • 1
  • 3
  • 3
  • 2
    I just update the "extras\google play service" through the "Android SDK Manager", i find the latest "google-play-services.jar" contain the "LocationClient.class" file; (and the old "google-play-services.jar" file just been download 5 days ago) – Jerry Sun May 19 '13 at 15:40

11 Answers11

25

Add to Gradle file (x.y.z - actual version of Google Play Services):

compile 'com.google.android.gms:play-services-location:x.y.z'
Atetc
  • 1,643
  • 19
  • 26
16

There is some problem with the last GPS lib. You have to use an older version than the latest(6.+). Try with an older version. I didn't see anything inside the doc deprecated or missing about the LocationClient.class.

compile 'com.google.android.gms:play-services:5.+'
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
  • 3
    This works because in 5.+ the now deprecated LocationClient is still included while in 6.5.+ they have replaced it with a GoogleApiClient, more info here http://stackoverflow.com/questions/24611977/android-locationclient-class-is-deprecated-but-used-in-documentation – TouchBoarder Dec 16 '14 at 12:00
  • good answer,but here find the version more actually: https://developers.google.com/android/guides/setup – David Hackro Nov 03 '15 at 22:20
13

LocationClient is deprecated. You have to use GoogleApiclient, like this:

1: Declare a GoogleApiClient variable

private GoogleApiClient mGoogleApiClient;

2: Instantiate

mGoogleApiClient = new GoogleApiClient.Builder(mThisActivity)
     .addApi(LocationServices.API)
     .addConnectionCallbacks(this)
     .addOnConnectionFailedListener(this)
     .build();

3: Implement Callback

public class YourClass extends BaseFragment implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener, LocationListener {

    @Override
    public void onConnectionFailed(ConnectionResult result) {
        // your code goes here
    }

    @Override
    public void onConnected(Bundle connectionHint) {
        //your code goes here
    }

    @Override
    public void onConnectionSuspended(int cause) {
        //your code goes here       
    }
}

4: Start to get Location Updates:

LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

5: Remove Location Updates:

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

6: Get Last Known Location:

private Location mCurrentLocation;

mCurrentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
3

As Location Client is deprecated the class is no more found in the package. We have to use the following instead

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks(){

    @Override
    public void onConnected(Bundle arg0) {
        // TODO Auto-generated method stub
        LocationRequest request = new LocationRequest();
        int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
        if (enableHighAccuracy) {
          priority = LocationRequest.PRIORITY_HIGH_ACCURACY;
        }
        request.setPriority(priority);

        LocationServices.FusedLocationApi.requestLocationUpdates(
                locationClient, request, new LocationListener() {

                  @Override
                  public void onLocationChanged(Location location) {

                    locationClient.disconnect();
                  }

        });
    }

    @Override
    public void onConnectionSuspended(int arg0) {
        // TODO Auto-generated method stub

    }
    })
.addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {

    @Override
    public void onConnectionFailed(ConnectionResult arg0) {
        // TODO Auto-generated method stub

    }
})
.build();
Aqib Mapari
  • 123
  • 5
2

Jeremie Petitjean's solution worked for me. Go into youbuild.grade file and configure your app for a lower version. This is what I used and it works now:

apply plugin: 'com.android.application'   
android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

defaultConfig {
    applicationId "<APPLICATION NAME>"
    minSdkVersion 9
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.android.support:appcompat-v7:19.0.1'
    compile 'com.google.android.gms:play-services:4.2+'
}
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
J Seaton
  • 59
  • 3
2

add this to your project `

implementation 'com.google.android.gms:play-services-location:16.0.0'//location services`
griffins
  • 7,079
  • 4
  • 29
  • 54
1

You need to update Google Play Service SDK and then use updated library.

Rikin Prajapati
  • 1,913
  • 2
  • 16
  • 23
1

check below links

The import com.google.android.gms cannot be resolved

How to add google-play-services.jar project dependency so my project will run and present map

Follow these steps and save your time

  1. Right Click on your Project Explorer.
  2. Select New-> Project -> Android Application Project from Existing Code
  3. Browse upto this path only - "C:\Users\User Name\Local\Android\sdk\extras\google\google_play_services"
  4. Be careful browse only up to - google_play_services and not up to google_play_services_lib

And this way you are able to import the google play service lib. Let me know if you have any queries regarding the same.

Community
  • 1
  • 1
Rakesh Soni
  • 10,135
  • 5
  • 44
  • 51
1

For the benefit of anyone working directly with Phonegap CLI. In your plugin.xml you require the line

<framework src="com.google.android.gms:play-services-location:+" />
DroidOS
  • 8,530
  • 16
  • 99
  • 171
1

Try this if you use Android Studio:

Right click on your app folder -> Open Module Settings -> Dependencies -> Click on the plus button -> Choose library dependency -> Search for "play-services" -> Double click on the com.google.android.gms:play-services

Press Ok and wait for Gradle to rebuild. If error occurs clean and rebuild your project. here

Community
  • 1
  • 1
Samir
  • 6,405
  • 5
  • 39
  • 42
0

Update the Google Play library to the latest version using the Android SDK Manager. In addition, I had to remove the library manually and add it again to my project following these steps. Version 3.1.36 contains:

enter image description here

The location folder:

enter image description here

You might have to update the ADT/SDK as well.

Miki
  • 1,625
  • 21
  • 29