mapbox / mapbox-events-android

Mapbox telemetry and core libraries for Android.
https://docs.mapbox.com/android/core/overview
MIT License
60 stars 48 forks source link

Mapbox: Failed to obtain last location update #396

Closed ctlmjg closed 4 years ago

ctlmjg commented 5 years ago

I created an Android App following this tutorial: https://docs.mapbox.com/android/maps/examples/show-a-users-location/

I did everything exactly as it says in the tutorial. I can open the map but when the app tries to give my current location I'm getting this error:

D/Mbgl-LocationComponentCompassEngine: Rotation vector sensor not supported on device, falling back to accelerometer and magnetic field. E/Mbgl-LocationComponent: Failed to obtain last location update java.lang.Exception: Last location unavailable at com.mapbox.android.core.location.MapboxFusedLocationEngineImpl.getLastLocation(MapboxFusedLocationEngineImpl.java:40) at com.mapbox.android.core.location.LocationEngineProxy.getLastLocation(LocationEngineProxy.java:25) at com.mapbox.mapboxsdk.location.LocationComponent.setLastLocation(LocationComponent.java:1315) at com.mapbox.mapboxsdk.location.LocationComponent.onLocationLayerStart(LocationComponent.java:1134) at com.mapbox.mapboxsdk.location.LocationComponent.enableLocationComponent(LocationComponent.java:1248) at com.mapbox.mapboxsdk.location.LocationComponent.setLocationComponentEnabled(LocationComponent.java:502) at com.example.android.myapplication.MainActivity.enableLocationComponent(MainActivity.java:74) at com.example.android.myapplication.MainActivity.access$000(MainActivity.java:25) at com.example.android.myapplication.MainActivity$1.onStyleLoaded(MainActivity.java:56) at com.mapbox.mapboxsdk.maps.MapboxMap.notifyStyleLoaded(MapboxMap.java:845) at com.mapbox.mapboxsdk.maps.MapboxMap.onFinishLoadingStyle(MapboxMap.java:205) at com.mapbox.mapboxsdk.maps.MapView$MapCallback.onDidFinishLoadingStyle(MapView.java:1178) at com.mapbox.mapboxsdk.maps.MapChangeReceiver.onDidFinishLoadingStyle(MapChangeReceiver.java:194) at com.mapbox.mapboxsdk.maps.NativeMapView.onDidFinishLoadingStyle(NativeMapView.java:1040) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:143) at android.os.Looper.loop(Looper.java:122) at android.app.ActivityThread.main(ActivityThread.java:5930) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) D/SensorManager: registerListener :: 0, K2HH Acceleration , 100000, 0, E/SensorManager: sensor or listener is null

Please help me! Thank you so much. I'm noob so please be kind. * @mapbox-machine @IodaMikeMapbox @vikimapbox @OulianaMapbox

LukasPaczos commented 5 years ago

Hey @catarinarpds, thanks for reaching out!

The only issue I'm seeing here is that you weren't able to obtain a location update. This is just a log, not an actual crash.

Would you be able to provide which version of the Maps SDK have you used and what device have you tested on?

Meanwhile, I'm transferring this issue to out telemetry repository.

andrlee commented 5 years ago

@catarinarpds any updates? also can you share your project's app/build.gradle file? thanks!

ctlmjg commented 5 years ago

Sorry I forgot to answer ! I guess the phone I used to run the app is not updated.

`apply plugin: 'com.android.application' apply plugin: "androidx.navigation.safeargs"

android { compileSdkVersion 28 defaultConfig { applicationId "com.example.android.cobig" minSdkVersion 22 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

} repositories { mavenCentral() }

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha03'
implementation 'com.google.android.material:material:1.1.0-alpha04'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation "androidx.navigation:navigation-fragment:2.1.0-alpha01"
implementation "androidx.navigation:navigation-ui:2.1.0-alpha01"
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.work:work-runtime:$versions.work"

// volley http library
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.code.gson:gson:2.8.2'

// Room components
implementation "android.arch.persistence.room:runtime:$versions.room"
annotationProcessor "android.arch.persistence.room:compiler:$versions.room"
androidTestImplementation "android.arch.persistence.room:testing:$versions.room"

// Lifecycle components implementation "android.arch.lifecycle:extensions:$versions.archLifecycleVersion" annotationProcessor "android.arch.lifecycle:compiler:$versions.archLifecycleVersion"

// mapbox components
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.6.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.2'

}`

I'm also having this error

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.MapView.onSaveInstanceState(android.os.Bundle)' on a null object reference when I click in the Recent Apps Button in my phone... Can u help me?

alfwatt commented 4 years ago

@nkukday please review alongside #419

Valid: https://github.com/mapbox/mobile-telemetry/issues/458

nkukday commented 4 years ago

From #419

@alfwatt we're pretty much adhering to google apis behavior with the only diff: if last location isn't available in google they return null and we throw an exception. Perhaps we need to document api signature to set expectation.

Docs