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 fi
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.+'
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:+" />
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);
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();
You need to update Google Play Service SDK and then use updated library.
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
And this way you are able to import the google play service lib. Let me know if you have any queries regarding the same.