onUpdate doesn't updates the value in the ref #3555
sulemanbutt10
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am making a feature where we follow the user location and whenever we click on add_point button, the app adds a point on the current coordinates.
The following location feature and add point feature is implemented.
MAIN ISSUE: I am facing an issue while updating the currentPosition ref in onUpdate callback.
Code for reference:
<MapboxGL.UserLocation
minDisplacement={1}
animated
androidRenderMode="gps"
showsUserHeadingIndicator
renderMode={UserLocationRenderMode.Native}
onUpdate={({ coords: { longitude, latitude } }) => {
const newCords = [longitude, latitude];
if (!currentPosition.current) {
if (fieldDetail?.id) {
moveCameraTo(fieldDetail.center_point);
} else {
moveCameraTo(newCords);
}
}
currentPosition.current = newCords;
setShouldRenderForcefullyOnUpdate((prev) => !prev);
setLocationFetched(true);
}}
/>
This function runs when i click on add point, but "currentPosition.current" sends the value which is few meters before from current location, while the following-location path.
const addPoint = () => {
onPressAddPoint(currentPosition.current ?? [0, 0]);
};
Beta Was this translation helpful? Give feedback.
All reactions