Following the examples from google developers site, I use FusedLocationProviderClient to get de last known location.
private FusedLocationProviderClient fusedLocationClient;
// ..
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
}
And on button click, I call:
fusedLocationClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last known location. In some rare situations this can be null.
if (location != null) {
// Logic to handle location object
myposition.setText(location.getLatitude() + ", " + location.getLongitude());
// ...
}
}
});
But, sometimes, it gives me a location that is far from current device geoposition. I've checked it on three different devices. I have declared:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
How should I use fusedlocation to get the best position with accuary? I've tried to change getlastlocation with getcurrentlocation but this last method is not available, although the docs said it is available.
question from:
https://stackoverflow.com/questions/65672232/fusedlocationproviderclient-returns-wrong-latitude-and-longitude 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…