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

Difference between SimpleLocation(this, false, false, 5000); and SimpleLocation(this, true, false, 5000); ? #4

Closed jasminesymonds closed 9 years ago

jasminesymonds commented 9 years ago

Hello Marco, I recently went through your wonderful library but I couldn't really figure out the difference between the above mentioned two.

Can we really rely on your library to find out the location in case of real Life and Death situations?

jasminesymonds commented 9 years ago

And is there a way to respond only when the current location is available? and not use the previously saved location?

ocram commented 9 years ago

Thanks for your feedback!

So you're asking for the meaning of the second parameter to the constructor? The JavaDoc for this library says:

@param requireFine whether to require fine location or use coarse location

If you pass true, you're forcing the library to use GPS. It will only try to use the fine location provider (GPS). If you didn't add the android.permission.FINE_LOCATION to your manifest, it will throw an exception. You will see that during development. Otherwise, it's your responsibility to check SimpleLocation#hasLocationEnabled() as described in the README. If location access is not enabled, you have to ask the user to do so, of course. There's no other way to do it.

If you pass false, you're saying that you don't care whether it's GPS location or network location. The library will first check if fine location (GPS) can be used, as it offers higher precision. If that provider is not available, it will just use coarse location (network) instead.

So if you want to use this for "real Life and Death situations", you probably have to pass true to get the most accurate position.

Regarding your second issue, i.e. receiving only new location data and ignore the cached positions, that's possible.

Please get the latest JAR from this project and pass a fifth parameter true to the constructor. This prevents the library from using a cached position. Note, however, that this means you'll have to wait some time for a location, especially with GPS.

If you want to know when the new location is available, you can either repeatedly check SimpleLocation#getPosition() against null or set up a listener like this:

location.setListener(new SimpleLocation.Listener() {

    @Override
    public void onPositionChanged() {
        // position has been updated

        // location.getLatitude()
        // location.getLongitude()
    }

});

If you want to build something for "real Life and Death situations", you'll want to do some intense and thorough testing of your app, and testing the location features should be a part of that.

Does that help?

jasminesymonds commented 9 years ago

How and where to pass the fifth parameter 'true' to the constructor? Can you please give an example...

ocram commented 9 years ago

Well, in the title of this issue, you wrote:

SimpleLocation location = new SimpleLocation(this, true, false, 5000);

Instead of that, just use this:

SimpleLocation location = new SimpleLocation(this, true, false, 5000, true);

You see, the fifth parameter was added. This only works with the latest JAR from this project, though.

jasminesymonds commented 9 years ago

Im sorry to say but on importing your new jar file I see an exclamatory sign in my project and cannot use it...

Your last jar file was working great...

ocram commented 9 years ago

Sorry, we cannot reproduce that problem. Everything is working fine on our end.

Please check your project setup! Thank you!