maplibre / maplibre-navigation-android

Maplibre Navigation SDK for Android
MIT License
92 stars 51 forks source link

locationComponent.lastKnownLocation always returns null #41

Closed jDilshodbek closed 8 months ago

jDilshodbek commented 1 year ago

mapBox.locationComponent.lastKnownLocation is always returning null unless manually requesting location update with location engine callback I am using MapLibre version 1.1.1

karussell commented 11 months ago

Have the same problem with Android 13 and MapLibre 3.0.0 and no location icon pops that in the notification bar as it usually happens when the location is requested.

What was your Android version?

Failed to obtain last location update
java.lang.Exception: Last location unavailable
    at com.mapbox.mapboxsdk.location.engine.MapboxFusedLocationEngineImpl.getLastLocation(MapboxFusedLocationEngineImpl.java:42)
    at com.mapbox.mapboxsdk.location.engine.LocationEngineProxy.getLastLocation(LocationEngineProxy.java:26)
    at com.mapbox.mapboxsdk.location.LocationComponent.setLastLocation(LocationComponent.java:1247)
    at com.mapbox.mapboxsdk.location.LocationComponent.onLocationLayerStart(LocationComponent.java:1045)
    at com.mapbox.mapboxsdk.location.LocationComponent.enableLocationComponent(LocationComponent.java:1154)
    at com.mapbox.mapboxsdk.location.LocationComponent.setLocationComponentEnabled(LocationComponent.java:285)
    at com.mapbox.services.android.navigation.testapp.NavigationUIActivity.enableLocationComponent(NavigationUIActivity.kt:135)
    at com.mapbox.services.android.navigation.testapp.NavigationUIActivity.onMapReady$lambda$6(NavigationUIActivity.kt:107)
    at com.mapbox.services.android.navigation.testapp.NavigationUIActivity.$r8$lambda$OL81pQG4o_zXu_XSfKerQ9f7G3s(Unknown Source:0)
    at com.mapbox.services.android.navigation.testapp.NavigationUIActivity$$ExternalSyntheticLambda3.onStyleLoaded(Unknown Source:2)
    at com.mapbox.mapboxsdk.maps.MapboxMap.notifyStyleLoaded(MapboxMap.java:962)
    at com.mapbox.mapboxsdk.maps.MapboxMap.onFinishLoadingStyle(MapboxMap.java:224)
    at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1346)
    at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:198)
    at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1124)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:335)
    at android.os.Looper.loopOnce(Looper.java:161)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7932)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
javaherisaber commented 9 months ago

@jDilshodbek @karussell I also have the same issue on Android 13, last location is always null

Fabi755 commented 9 months ago

Can you give me more details, what you try to do, and how you want to access the last location data?

Any other Android versions, on that bug exists?

javaherisaber commented 9 months ago

@Fabi755 I just cloned the repo and ran the project, making no changes to it I reproduced it on an emulator with API 33

Fabi755 commented 8 months ago

There are no issues with this implementation.

The location component (of maplibre-gl for android) is trying to get the last known location on initialization. last known location means, that any other app (or your own code) must request and receive a location before. This call is not requesting the current GPS position, only the last one that was fetched.

If you start a fresh installed emulator, there is no previous location data in the system. I don't know what happens by a OS restart.

The missing last location is logged as error. Maybe a little too much, but that's all.

To solve this problem, you can open a map app (example Google Maps) before testing the demo app. Or request the location by yourself in your custom app code.