I'm trying to get a user's location and it keeps updating from time to time, searching, I found this method, but I can not just do this with the current value of the array, it concatenates (push) and adds infinitely .. does anyone know how I can fix this?
var array = [];
navigator.geolocation.watchPosition(function(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var vel = position.coords.speed;
array.push(lat, lon, vel);
locationCode()
});
function locationCode() {
console.log(array)
alert(array[0]);
}