1

i implemented the method used in Lib android this, see:

  fusedLocationProviderClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
            @Override
            public void onSuccess(Location location) {
                if(location != null) {
                    localidade = location;
                    Toast.makeText(getApplicationContext(), "Local correto", Toast.LENGTH_LONG).show();
                }

                    Toast.makeText(getApplicationContext(), "Localidade vazia", Toast.LENGTH_LONG).show();
            }
        });

However, within OnSuccess the result is ALWAYS null, I am testing on my mobile (9.0 android) with LOCAL(gps) mode on and still returns null, my manisfest has the necessary permissions: <uses-permission android: name = "android.permission .ACCESS_FINE_LOCATION "/>

In my view nothing is wrong, so why ALWAYS null?

Community
  • 1
  • 1
luke cross
  • 321
  • 1
  • 2
  • 19

1 Answers1

0

Last known location is registered known location by the user. If you read on the location page it states that last known location can be null in certain situations; in those scenarios it is advised you request location updates. Following is taken from the page:

The location object can be nullin the following situations:

Location is disabled in the device settings. The result may nulleven be that the last location was retrieved earlier, because disabling the location also clears the cache. The device never recorded its own location, which happens when the device is new or when it has been restored to factory settings. The Google Play Services platform on the device has been restarted and no active Fused Location Provider API clients have requested location after services have been restarted. To avoid this situation, create a new customer and request location updates.

The_Martian
  • 3,684
  • 5
  • 33
  • 61