I am trying to update the marker coordinates using socket io client, theres no error present but the only problem is that the marker location in the map is not accurate as what expected.
please check code snippet below
Mapview component:
<MapView
style={styles.map}
region={{
latitude: lat,
longitude: lng,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
<UrlTile
urlTemplate="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
maximumZ={19}
/>
<Marker
coordinate={{ latitude: lat, longitude: lng }}
title={"San Francisco"}
description={"This is a description of the oten"}
/>
</MapView>
useEffect function :
const [lat, setLat] = useState(10.330121);
const [lng, setLng] = useState(123.900298);
useEffect(() => {
const socketIo = io(SOCKET_URL);
socketIo.on("testLocation", (data) => {
console.log("testLocation", data);
setLat(data.lat);
setLng(data.lng);
});
// - disconnect on unmount
return () => {
socketIo.disconnect();
};
}, []);
New contributor
Eduardo Omega Jr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.