Can't explore map when followUserLocation
is set on Android
#658
-
Describe and reproduce the BugOn ios simulator, when dragging off the map and zooming out, it stops following the user location, but on android studio, when zooming out, after a few seconds, it snaps back the the user location, making so that you can't explore the map. is there some way to fix this? <Camera
ref={cameraRef}
followUserLocation={true}
followZoomLevel={16}
/> here's a screen recording @maplibre/maplibre-react-native Version10.0.1 Which platforms does this occur on?Android Emulator Which frameworks does this occur on?Expo Which architectures does this occur on?New Architecture Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
I assumed that this behavior was intended, so I treat Camera.followUserLocation as a hard toggle on the camera tracking behavior... But the fact that it behaves differently on iOS is definitely strange! |
Beta Was this translation helpful? Give feedback.
-
Yeah, it's kinda weird. But I managed to make a workaround by setting the |
Beta Was this translation helpful? Give feedback.
-
Can you reproduce this on the old architecture? In my testing it seems to behave the same – I can freely move around and the camera is not realigned, when a new user location is detected. I've used this example: import { Camera, MapView, UserLocation } from "@maplibre/maplibre-react-native";
export function BugReport() {
return (
<MapView style={{ flex: 1 }}>
<Camera followUserLocation followZoomLevel={16} />
<UserLocation />
</MapView>
);
} Anyway, to keep you prop in sync with the import { Camera, MapView, UserLocation } from "@maplibre/maplibre-react-native";
import { useState } from "react";
export function BugReport() {
const [followUserLocation, setFollowUserLocation] = useState(true);
return (
<MapView style={{ flex: 1 }}>
<Camera
followUserLocation={followUserLocation}
followZoomLevel={16}
onUserTrackingModeChange={(event) => {
if (!event.nativeEvent.payload.followUserLocation) {
setFollowUserLocation(false);
}
}}
/>
<UserLocation />
</MapView>
);
} |
Beta Was this translation helpful? Give feedback.
-
Thanks, it worked. I think it has something to do with my code, because I commented everything out and now it works. I was unable to get it to work without adding this to my <UserLocation
renderMode={UserLocationRenderMode.Native}
/> and for some reason, the location updates only if I add a useEffect that uses expo location like this, did I setup my permissions wrong? also opening google maps then switching back to the app works to? 🤨 "android": {
"permissions": [
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.FOREGROUND_SERVICE",
"android.permission.ACCESS_BACKGROUND_LOCATION"
]
} useEffect(() => {
const getCurrentLocation = async () => {
let location_data = await Location.getCurrentPositionAsync({
accuracy: Location.Accuracy.Highest,
});
setLocation(location_data);
};
const interval = setInterval(() => {
getCurrentLocation();
}, 1000);
return () => clearInterval(interval);
}, []); |
Beta Was this translation helpful? Give feedback.
-
Also, now that the user can explore the map when panning the map, how can I get back to following the user location? |
Beta Was this translation helpful? Give feedback.
-
Also I have a question, is it possible to implement a scrollbar to zoom in and out of the map? |
Beta Was this translation helpful? Give feedback.
Can you reproduce this on the old architecture? In my testing it seems to behave the same – I can freely move around and the camera is not realigned, when a new user location is detected.
I've used this example:
Anyway, to keep you prop in sync with the
Camera
you should use theonUserTrackingModeChange
event, something like this: