Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26675] Android: Add getLastLocation to FusedLocationProvider

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sRelease 10.2.0
Componentsn/a
Labelsandroid, geolocation
ReporterMichael Gangolf
AssigneeJoshua Quick
Created2018-12-20T18:28:38.000+0000
Updated2021-10-19T20:44:53.000+0000

Description

The current implementation of the FuseLocationProvider is not using the getLastLocation() method: https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/geolocation/src/java/ti/modules/titanium/geolocation/android/FusedLocationProvider.java According to https://developer.android.com/training/location/retrieve-current#java you can use getLastLocation() on the provider. Adding this to the Java file mentioned above:
fusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
    @Override
    public void onSuccess(Location location)
    {
        // Got last known location. In some rare situations this can be null.
        if (location != null) {
            Log.i("Fused", "Location: " + location);
        }
    }
});
works fine, it just needs to transfer those values to the JS location event .

Comments

  1. Sharif AbuDarda 2018-12-20

    Thanks for the feature ticket. Our engineers will look into it. Thanks.
  2. Michael Gangolf 2021-10-19

    PR: https://github.com/appcelerator/titanium_mobile/pull/13133 had this in my queue for a longer time :)
  3. Ahmed Mohamed 2021-10-19

    getLastLocation will get the last cached location in the device and that's sometimes far from the current location. let us say an app request location data on day 1 so this location will be the last location requested on the device then after 30 days if no other app make a new location request then getLastLocation will get that same old location that was requested since 30 days ago So I don't think getLastLocation should fire location If you want to try it please use my ti.locationservices module https://github.com/AhmedMSayed/ti.locationservices
  4. Michael Gangolf 2021-10-19

    Thanks for the feedback [~ahmed.mohamed20320]! I have to check it again but shouldn't that be covered by the included timestamp? But you are right, if you don't check that it can be very wrong. I'll have a look again. BTW: I'm using the userLocation event of ti.map since that is using internal map stuff by Google and returned a proper fix quicker than geoolaction in my tests.

JSON Source