I am trying to get an exact GPS location on the click of a button. I am using the fusesLocationProviderClient and have FINE_LOCATION permission.
private void getCurrentGPSLocation() {
// get the new location from the fused client
// update the UI - i.e. set all properties in their associated text view items
//Initialize new location request
LocationRequest locationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10000)
.setFastestInterval(1000)
.setNumUpdates(1);
//Initialize location call back
LocationCallback locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
//Initialize location1
Location location1 = locationResult.getLastLocation();
//Set Accuracy
double accura1 = location1.getAccuracy();}
};
//Request location updates
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
fusedLocationProviderClient.requestLocationUpdates(locationRequest
, locationCallback, Looper.myLooper());
}
Then I am getting the coordinates from the location1 variable as I am getting accuracy from it. The problem is that this is very unprecise as I am getting an accuracy of 800-1000m. After having opened GoogleMaps for a few seconds and then returning to my app calling getLastLocation(); with another button (not part of my code sample), I am getting an accuracy of 4-5m. When using my code again the accuracy again is 800-1000m. So my question is, how I can change my code to get this kind of accuracy into my getCurrentGLSLpcation() method.