in your on-press handler, you never actually stop the updates, so you’ll get another position in ~ 3600 seconds (as specified by the minInterval), and send another btn-pos event (even if there was no new button press)
your “normal routine” calls startUpdates again, which actually overwrites your previous startUpdates, so with this code, I don’t think you’ll be getting anybtn-pos events
I think to begin with, I’d try doing something like this:
… and in both of the location updates callbacks, remember to stopUpdates:
location.startUpdates((position) => {
cloud.enqueue('...', { // both btn-pos and auto-pos
lat: position.lat,
long: position.long,
at: new Date()
});
sync.now();
location.stop(); // <=========
// ...
This still doesn’t prevent the button-press-initiated and the timer-initiated location updates from overlapping and interfering with each other (a race condition of sorts), but it’s a start and should work most of the time (: And then you can work on making it more resilient.
On another note, it might also be helpful for you to read something about promises and asynchronous programming in JavaScript, because this:
location.startUpdates(
// ...
);
print("Location sent, now registering back to normal routine");
… doesn’t actually work this way. startUpdates will return immediately, and just schedule the updates to happen in the future, and then your app will immediately move to the next instruction, the print. So actually, you’ll get “Location sent” message in your console, but that’s not gonna be true, because the location updates didn’t necessarily happen yet.
startUpdates returns a thing called a promise, which you can use to actually schedule some code to run when updates do stop:
var promise = location.startUpdates(
// ...
);
promise.then(() => {
print("Location sent, now registering back to normal routine");
});
// or shorter:
location.startUpdates(
// ...
).then(() => {
print("Location sent, now registering back to normal routine");
);
And I have a question, with this methodology, my device storage is exceeding. I see location.stopUpdates() doesn’t stop the location updates making my device out of storage.
My use case is to click a button and send the current location only and then stop. So it should be like pushing the button and sharing the current location and bingo. Close.
The other use case along with the above one is, that my device automatically share the current location at the time of sending, daily.