I am trying to get GPS of smartphone like the following code:
In Activity.java , I use the following code to get GPS.
private GPSClass gps;
gps.getGPSLocation();
In GPSClass.java
public void getGPSLocation(){
FusedLocationProviderClient mLocationClient = LocationServices.getFusedLocationProviderClient(mContext);
mLocationClient.getLastLocation().addOnCompleteListener(mContext, new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task) {
if(task.isSuccessful()){
mLocation = task.getResult();
Log.i("getLocation---LOCATION", mLocation.getLatitude() + "/"
+ mLocation.getLongitude());
}
}
});
}
But how to return value in GPSClass.java ?
I have try to replace
public void onComplete
instead of
public Location onComplete
But it show the error
'onComplete(Task<Location>)' in 'Anonymous class derived from com.google.android.gms.tasks.OnCompleteListener' clashes with 'onComplete(Task<TResult>)' in 'com.google.android.gms.tasks.OnCompleteListener'; attempting to use incompatible return type
Did I miss something? How to return value in OnCompleteListener? Thanks in advance.