I’m trying to build an app for running, so I’m trying to track the user position on a google map, but I get the position from the android device every 6/8 seconds, the strange thing is that on web it works perfectly. this is my code:
if (!this.isTracking) {
this.startTracking();
} else {
this.stopTracking();
}
}
// Use Capacitor to track our geolocation
startTracking() {
this.isTracking = true;
this.label = "Stop Tracking";
this.watch = Geolocation.watchPosition(
{
enableHighAccuracy: true,
maximumAge: 2000,
timeout: 0,
},
(position, err) => {
if (position) {
let date = new Date().toLocaleTimeString();
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
this.markerLat = position.coords.latitude;
this.markerLng = position.coords.longitude;
this.addNewLocation(
position.coords.latitude,
position.coords.longitude,
date
);
this.cdRef.detectChanges();
}
}
);
}
// Unsubscribe from the geolocation watch using the initial ID
stopTracking() {
Geolocation.clearWatch({ id: this.watch }).then(() => {
this.isTracking = false;
this.label = "Start Tracking";
});
}
// Save a new location to Firebase and center the map
addNewLocation(lat, lng, time) {
this.points.push({
lat,
lng,
time,
});
this.pointsView.unshift({
lat,
lng,
time,
});
}