Umakant Angadi
Umakant Angadi

Reputation: 99

What is best way to get current accurate location in android?

I am trying to implement getting the current location. And I have used these both codes.

 mFusedLocationClient =
 LocationServices.getFusedLocationProviderClient(this);
 mFusedLocationClient.getLastLocation()...

Location accuracy is 2000 meters

and

ReactiveLocationProvider locationProvider = new  ReactiveLocationProvider(context);
locationProvider.getLastKnownLocation()...

Location acccuracy is 100 to 200 meters.

I felt reactive location is most accurate. Is there any best way to get accurate current location. and Can any one explain why google code is not showing exact location?

Upvotes: 2

Views: 3189

Answers (2)

Nayan Srivastava
Nayan Srivastava

Reputation: 3725

Both of them are correct, though out of my experience as well Reactive is more accurate but in general, they provide more accuracy when you give them time to settle. What that mean is if you instantiate LocationProvider and instantly try to query the location it may not provide the most accurate location, I would rather suggest to give user a refresh button to see if the location now is more accurate than the previous one. WhatsApp location sender is a fine example of it, users can refresh current location to find more accurate coordinates.

Upvotes: 0

Kuls
Kuls

Reputation: 2067

You can create LocationRequest ans setPriority with LocationRequest.PRIORITY_HIGH_ACCURACY and it will high accuracy. Though accuracy is depends on GPS as sometimes I get 10 meters of accuracy.

 protected void createLocationRequest() {
        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(INTERVAL);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    }

To know more you can refer Fused location provider

Upvotes: 1

Related Questions