delight-im / Android-SimpleLocation

Utility class for easy access to the device location on Android
Apache License 2.0
200 stars 75 forks source link

Works only first time then It does not work #36

Closed Mirodil closed 5 years ago

Mirodil commented 5 years ago

Here is exemple code:

location = new SimpleLocation(this);

    // if we can't access the location yet
if (!location.hasLocationEnabled()) {
        // ask the user to enable location access
        SimpleLocation.openSettings(this);
    }

location.beginUpdates();

location.setListener(new SimpleLocation.Listener() {
        public void onPositionChanged() {
            Log.d("Location", location.getLatitude()+":"+location.getLongitude()+":"+location.getAltitude());
        }
});

When I open emulator and change Latitude or Longitude first time it fires listener but then it does not.

ocram commented 5 years ago

The emulator is always different than a real device. So make sure to check on a real device as well, if you get a chance.

Apart from that, please try the extended constructor variants that let you specify an update interval manually.

Finally, if location isn’t enabled (and you open the settings), starting the location updates doesn’t make any sense. But if the user returns from the settings, e.g. in onResume, it might make sense to start the updates again.

Hope that helps!