maps: [Bug]: UserLocation doesn't work with other GeoLocation Services (Android)

Mapbox Implementation

Mapbox

Mapbox Version

10

Platform

Android

@rnmapbox/maps version

10.0.0-beta.11

Standalone component to reproduce

import { StyleSheet, View ,Text,PermissionsAndroid, SafeAreaView} from 'react-native';
import Mapbox, {UserLocationRenderMode} from '@rnmapbox/maps'
import { useEffect, useState } from "react";

export function Map(){

  const [location,setLocation] = useState(null);
  const [hasLocationPermissions,sethasLocationPermissions] = useState(false)

  const requestLocationPermission = async  () => 
  {
    try {
      const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,

      )
      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        sethasLocationPermissions(true)
        console.log("You can use the location")
        alert("You can use the location");
      } else {
        console.log("location permission denied")
        alert("Location permission denied");
      }
    } catch (err) {
      console.warn(err)
    }
  }

  useEffect(()=>{
      requestLocationPermission()
  },[])



    return(
        <SafeAreaView style={styles.container}>
             <Mapbox.MapView style={styles.map} >
              <Mapbox.PointAnnotation
                draggable={true}
                onDragEnd={feature => {
                  console.log(feature);
                  setLocation({
                    latitude: feature.geometry.coordinates[1],
                    longitude: feature.geometry.coordinates[0],
                  });
                }}
                coordinate={ [
                  -1.510311133796023,
                  53.816142903704616
                        ]}
              >
             <View style={{
                height: 30,
                width: 30,
                backgroundColor: '#00cccc',
                borderRadius: 50,
                borderColor: '#fff',
                borderWidth: 3
                }} />
      
     
              </Mapbox.PointAnnotation>
              
              
                
                    <Mapbox.UserLocation
                    visible={true}
                    androidRenderMode={'compass'}
                    showsUserHeadingIndicator={true}
                    onUpdate={newLocation => {
                      console.log(newLocation)
                    }}
                />
             
              
             
        </Mapbox.MapView>
        </SafeAreaView>
    )
}

Observed behavior and steps to reproduce

This started when i switched to mac os, i have a project with rnmapbox and react-native-geolocation-service in linux android was working fine with both i could get updates from UserLocation but in mac os that doesn’t work anymore so i tried to figure out what was wrong, i started a new project and i could get update locations without react-native-geolocation-service installed, so i installed another lib @react-native-community/geolocation and still happens the same the UserLocation didn’t work anymore, i only can work with UserLocation on android without any geolocation lib.

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 28 (6 by maintainers)

Most upvoted comments

Throughout this issue there are quite a few different/unclear problems stated. Therefore it’s hard to determine, who is confirming which problem. I figured at least one specific case described by @FrancoisVA in our app too:

The UserLocation component’s onUpdate function only fires once (on load) but doesn’t fire again when the user location changes. Only occurs on Android.

To further clarify, the puck on the map does not update for normal render mode (either custom children or the default from rnmapbox). Using native render mode will give a moving puck. For both render modes onUpdate is only triggered once. I’m on the #main Branch equivalent to v10.0.7-rc.1.

This occurs due to no displacement beeing passed. So anyone who’s experiencing the aforementioned problem, please try the following:

       <MapboxGL.UserLocation
          minDisplacement={1}
          renderMode={UserLocationRenderMode.Normal}
          onUpdate={() => console.log("location changed")}
        />

Please give feedback 👍 👎 if this workaround works (only if you are experiencing this very same problem). You should be seeing a moving puck and getting “location changed” regularly, if you are simulating/moving your location.

@mfazekas sadly I’m still not able to reproduce the bug in the example. I can only recreate it in our expo project. Through prebuild I added error logging to the LocationManager onFailure which gave the following error:

com.mapbox.common.location.compat.LocationEngineException: invalid displacement: -1.0
        at com.mapbox.common.location.compat.LocationEngineImpl$notifyConsumersError$lambda-1$$inlined$postOrCall$1.run(LocationEngineImpl.kt:361)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

So under some circumstances when displacement is passed as -1.0 Mapbox SDK throws an error.

I’m having the same issue, but adding useEffect(() => {MapboxGL.locationManager.start()},[]} doesn’t seem to do the trick for me.

Downgraded to 10.0.0-beta.70 and then it works again.

This is also a problem I have been seeing intermittently for more than a year with our build. No one has been able to fix it so far; currently working with someone to try to build a work around for this case. Any help in solving this would be amazing for us!

Throughout this issue there are quite a few different/unclear problems stated. Therefore it’s hard to determine, who is confirming which problem. I figured at least one specific case described by @FrancoisVA in our app too:

The UserLocation component’s onUpdate function only fires once (on load) but doesn’t fire again when the user location changes. Only occurs on Android.

To further clarify, the puck on the map does not update for normal render mode (either custom children or the default from rnmapbox). Using native render mode will give a moving puck. For both render modes onUpdate is only triggered once. I’m on the #main Branch equivalent to v10.0.7-rc.1.

This occurs due to no displacement beeing passed. So anyone who’s experiencing the aforementioned problem, please try the following:

       <MapboxGL.UserLocation
          minDisplacement={1}
          renderMode={UserLocationRenderMode.Normal}
          onUpdate={() => console.log("location changed")}
        />

Please give feedback 👍 👎 if this workaround works (only if you are experiencing this very same problem). You should be seeing a moving puck and getting “location changed” regularly, if you are simulating/moving your location.

@mfazekas sadly I’m still not able to reproduce the bug in the example. I can only recreate it in our expo project. Through prebuild I added error logging to the LocationManager onFailure which gave the following error:

com.mapbox.common.location.compat.LocationEngineException: invalid displacement: -1.0
        at com.mapbox.common.location.compat.LocationEngineImpl$notifyConsumersError$lambda-1$$inlined$postOrCall$1.run(LocationEngineImpl.kt:361)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

So under some circumstances when displacement is passed as -1.0 Mapbox SDK throws an error.

Had the issue and setting minDisplacement={0} solved it. In doc, it is still said that default is 0 !

@ mfazekas I tested on 10.0.0-beta.69, and the issue is not present there. There might be a more recent build (between 10.0.0-beta.69 and 10.0.0-beta.74) that also works, but I haven’t had time to test on more versions.

I tried go to that version and the issue is still present for me. “yarn add @rnmapbox/maps@10.0.0-beta.69”

@0xcD3v I think it might be a cache issue with your package or something, but I don’t know enough about RN to help you. Try deleting all packages and re-installing and cleaning the project I guess. I tried on 10.0.0-beta.70 and that works as well.

@mfazekas it looks like this issue is present on all versions after 10.0.0-beta.70, I guess some change between 70 and 71 is wat caused the issue. Please let me know if this is something you will be able to resolve or if we will have to get rid of the other geolocation packages.

@FrancoisVA Is working for me now the 10.0.0-beta.70

@FrancoisVA thank for checking looking at the diff of 70 and 71 v10.0.0-beta.70…v10.0.0-beta.71 I see that mapbox was bumped to 10.11.1 If you can check if downgrading the mapbox libs with RNMapboxImpl as describe in docs helps or not:

https://github.com/rnmapbox/maps/blob/main/android/install.md#using-non-default-mapbox-version

 RNMapboxMapsLibs = {
            implementation 'com.mapbox.maps:android:10.10.0'
            implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:6.10.0'
        }

@mfazekas I tried to do that, and the problem persists i updated to /maps-10.0.0-rc.8 and on ios i was unable to install " rnmapbox-maps (from ../node_modules/@rnmapbox/maps) was resolved to 10.0.0-rc.8, which depends on MapboxMaps (~> 10.12.0)"

(update): -> i could resolve the problem of ios by pod update.

-> idk if the problem is cache of project or not, but i already removed the node modules, yarn clean cache, watchman clean and still persists

->Another issue i spotted it is when we open the app for the first time on android and i ask for permission the user location throws an error even if i accept the permisions, that isue doesn’t occur on ios.

@0xcD3v Sorry it’s a community project, with limited resources.