Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

java - FusedLocationProviderClient returns wrong latitude and longitude

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...