2

When I open the app it reports the coordinates of the device. Then I change the coordinates using the emulator's menu, close and reopen the app, and the old coordinates still show. After opening Google Maps, for a while the location icon is grey and then it jumps to the new location. Then I open my app again and it's in the correct place now.

The code I'm using is really simple. Here it is:

FusedLocationProviderClient fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
    fusedLocationClient.getLastLocation().addOnCompleteListener(
            new OnCompleteListener<Location>() {
                @Override
                public void onComplete(@NonNull Task<Location> task) {
                    Location location = task.getResult();

                    Toast.makeText(MainActivity.this, "" + location.getLongitude(), Toast.LENGTH_LONG).show();
                }
            }
    );

I assume Google Maps is somehow force refreshing the location. How can I do this on my own app?

Lucas
  • 668
  • 1
  • 5
  • 17
  • _"I assume Google Maps is somehow force refreshing the location."_ Yes, precisely. _"How can I do this on my own app?"_ Request location updates and don't rely on `getLastLocation()`. – Markus Kauppinen Apr 12 '20 at 16:28
  • Same issue here... It's giving the same location periodically even after changing location in emulator - only refreshes after opening GoogleMaps – csaron92 May 09 '20 at 18:14

0 Answers0