Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find the class com.google.android.gms.location.LocationClient (android)

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"?

like image 782
Jerry Sun Avatar asked May 19 '13 15:05

Jerry Sun


3 Answers

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

compile 'com.google.android.gms:play-services-location:x.y.z'
like image 124
Atetc Avatar answered Nov 18 '22 07:11

Atetc


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.+'
like image 16
Jeremie Petitjean Avatar answered Nov 18 '22 05:11

Jeremie Petitjean


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);
like image 13
Pedro Magalhães Avatar answered Nov 18 '22 05:11

Pedro Magalhães