delight-im/Android-SimpleLocation

Course location working, but not Fine location

Closed this issue · 2 comments

When i set the requireFine parameter of any of the constructors to true, i get 0.0 coordinates, but when i use the single-param constructor(defaulting requireFine to false), i get actual coordinates(i havnt plotted them onto a map so i cant say how accurate they are).

My usage:
-GPS settings enabled on phone, check
-Manifest permissions(course & fine), check
-calling beginUpdates in onResume(calling endUpdates immediately after i get the coordinates), check
-checking if hasLocationEnabled before getting coordinates, check

ocram commented

Thanks for this well-written report of your problem!

I don't think there's anything wrong with what you're doing. It seems that you've done precisely what is described in the README.

Your problem, i.e. receiving an empty location only, might just be because the fine location (GPS) takes a while to deliver the first location update. There's nothing you can do about it. But you can listen for the updates so you know exactly when the first location update arrives:

mySimpleLocation.setListener(new Listener() {

    @Override
    public void onPositionChanged() {
        // we've got a location update
    }

});

This way, you are informed whenever a new location update is available. In your case, you may want to wait for the first update, get the position there, and then just stop the updates. But you can't just get the location a second after you've enabled the GPS -- the position will just not be there yet.

By the way, the passive parameter of the constructor should be false by default. Make sure you didn't set it to true. That's because, when in passive mode, your device doesn't actually request new location updates but instead only retrieves locations that have previously been requested by other components or apps.

Apart from that, you can also specify an interval in milliseconds when calling the constructor. The default should be about 10 minutes. So if you need more frequent updates, set this to a lower value manually.

All in all, I admit the README needs some improvement to include these notes ;)

Hope this helps!

Great, thanks for the detailed response. Will try out your suggestion and let you know how that goes.