How do I finish this function by clicking the finish button?

Asked

Viewed 113 times

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?

  • Has been resolved.

  • So put the answer so that other people who have the same doubt know how to solve.

  • The Finish button calls a getLocStop() function that will clear the variable this.range as follows: getLocStop(){ window.clearInterval(this.interval); } }

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.