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

Not getting location when asking a new one #12

Closed facundomedica closed 7 years ago

facundomedica commented 8 years ago

If I use this constructor:

public SimpleLocation(final Context context, final boolean requireFine, final boolean passive, final long interval, final boolean requireNewLocation) {...}

Passing true to requireNewLocation I can't get a location and onLocationChanged is never called.

But using works perfectly:

public SimpleLocation(final Context context, final boolean requireFine, final boolean passive, final long interval) {
    this(context, requireFine, passive, interval, false);
}

EDIT: Well, not that perfectly in a Samsung Galaxy S4 mini

EDIT 2: I realized that it's reaching the catch inside this function, but I can't check the error (Maybe I'll have to run the source):

    private Location getCachedPosition() {
        if (mCachedPosition != null) {
            return mCachedPosition;
        }
        else {
            try {
                return mLocationManager.getLastKnownLocation(getProviderName());
            }
            catch (Exception e) {
                return null;
            }
        }
    }

Maybe a bug? Thanks!

ocram commented 8 years ago

Passing true to requireNewLocation I can't get a location and onLocationChanged is never called.

Setting requireNewLocation to true prevents you from being able to use any cached locations. Thus a new location must indeed be detected for this configuration. This may take some time. But no matter how many seconds it takes, there really should be some result.

Are you sure you've set up your callback correctly and logged something in the onLocationChanged method of that callback?

What about your device configuration? Is network location or GPS location set up correctly? Does it work with other apps?

public SimpleLocation(final Context context, final boolean requireFine, final boolean passive, final long interval) {
    this(context, requireFine, passive, interval, false);
}

Can you show how you call that method instead of how it's defined by this library? That would be more helpful (in this and the previous case). Thanks!

I realized that it's reaching the catch inside this function, but I can't check the error (Maybe I'll have to run the source)

That's definitely some helpful information. Thank you!