Reputation: 158
I am facing a issue with getting latitude longitude using FusedLocationProviderClient only in Android Pie, I got the correct location below Android Version 9.0(Pie)
Every time I called getLocation() FusedLocationProviderClient provides same lat long.
mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if (location != null) {
wayLatitude = location.getLatitude();
wayLongitude = location.getLongitude();
Log.e("Location11", "" + String.format(Locale.US, "%s - %s", wayLatitude, wayLongitude));
} else {
mFusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, null);
}
}
});
I got same lat long everytime. like latitude- 28.303303303303 longtitude- 77.411411411
Upvotes: 4
Views: 1487
Reputation: 55
Provide Permission Both:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
ACCESS_FINE_LOCATION
will give proper result.
Upvotes: 1
Reputation: 413
Use FusedLocationProviderApi and set LocationRequest priority to PRIORITY_HIGH_ACCURACY
This is newest API for accurate location fetch and google suggest to use the same.
Check Accuracy details (Android Location Providers - GPS or Network Provider?)
Basically Google play services API has intelligence to get accurate location by fusing GPS+NetworkProvider+passive providers.
Upvotes: 2