1
ion-button block (click)="getLoc()">start
ion-button block (click)="getLoc()">Finish
When I click on the "Start" button, this function grabs the current location every 10 seconds, as I do to stop collecting the location by clicking the finish button?
getLoc(){
var intervalo = window.setInterval(function() {
// corpo da funcao
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function success(pos) {
var crd = pos.coords;
console.log('Sua localização é');
console.log(`Latitude : ${crd.latitude}`);
console.log(`Longitude: ${crd.longitude}`);
//console.log(`More or less ${crd.accuracy} meters.`);
// console.log(crd.latitude);
};
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
};
navigator.geolocation.getCurrentPosition(success, error, options);
},5000);
}
Can put more information in the code?
– durtto
Has been resolved.
– Ademário Marcolino
So put the answer so that other people who have the same doubt know how to solve.
– durtto
The Finish button calls a getLocStop() function that will clear the variable this.range as follows: getLocStop(){ window.clearInterval(this.interval); } }
– Ademário Marcolino