I am using Geolocation service and pushed coordinate changes in to an array variable but when I use set state it throws an error it says cannot add new property.
here is my code :
let dataarray = []
const startTrackingFunction = async () => {
await Geolocation.watchPosition(
position => {
const crd = position.coords;
setPosition({
latitude: crd.latitude,
longitude: crd.longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
});
dataarray.push(crd);
setCoordinates(dataarray);
},
error => {
console.log(error);
},
{
showLocationDialog: true,
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 0,
distanceFilter: 0,
});
setTracking(true);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>