|
|
@ -41,77 +41,79 @@ var geoerrorcount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
var mapLocationControlStarted = false;
|
|
|
|
var mapLocationControlStarted = false;
|
|
|
|
|
|
|
|
|
|
|
|
if ("geolocation" in navigator) {
|
|
|
|
function setupPositionWatcher() {
|
|
|
|
navigator.geolocation.watchPosition(function (position) {
|
|
|
|
if ("geolocation" in navigator) {
|
|
|
|
userPosition.coords = position.coords;
|
|
|
|
navigator.geolocation.watchPosition(function (position) {
|
|
|
|
userPosition.updated = time();
|
|
|
|
userPosition.coords = position.coords;
|
|
|
|
setStorage("user_latitude", userPosition.coords.latitude);
|
|
|
|
userPosition.updated = time();
|
|
|
|
setStorage("user_longitude", userPosition.coords.longitude);
|
|
|
|
setStorage("user_latitude", userPosition.coords.latitude);
|
|
|
|
if (mapLocationControlStarted) {
|
|
|
|
setStorage("user_longitude", userPosition.coords.longitude);
|
|
|
|
// Don't refresh at an interval less than ten seconds
|
|
|
|
if (mapLocationControlStarted) {
|
|
|
|
var currentTimestamp = Math.floor(Date.now() / 1000);
|
|
|
|
// Don't refresh at an interval less than ten seconds
|
|
|
|
if (lastGpsUpdateTimestamp < (currentTimestamp - 10)) {
|
|
|
|
var currentTimestamp = Math.floor(Date.now() / 1000);
|
|
|
|
updateDistances(position.coords.latitude, position.coords.longitude);
|
|
|
|
if (lastGpsUpdateTimestamp < (currentTimestamp - 10)) {
|
|
|
|
|
|
|
|
updateDistances(position.coords.latitude, position.coords.longitude);
|
|
|
|
var alertinterval = getStorage("alertinterval");
|
|
|
|
|
|
|
|
if (alertinterval == null) {
|
|
|
|
var alertinterval = getStorage("alertinterval");
|
|
|
|
alertinterval = 30;
|
|
|
|
if (alertinterval == null) {
|
|
|
|
} else {
|
|
|
|
alertinterval = 30;
|
|
|
|
alertinterval = alertinterval * 1;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
alertinterval = alertinterval * 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastGpsUpdateTimestamp = currentTimestamp;
|
|
|
|
lastGpsUpdateTimestamp = currentTimestamp;
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
for (var i = 0; i < packages.length; i++) {
|
|
|
|
if (packages[i].distance * 1 < getStorage("alertradius") * 1) {
|
|
|
|
if (packages[i].distance * 1 < getStorage("alertradius") * 1) {
|
|
|
|
|
|
|
|
|
|
|
|
if (packages[i].lastAlert > currentTimestamp - alertinterval) {
|
|
|
|
if (packages[i].lastAlert > currentTimestamp - alertinterval) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (getUndeliveredCount(packages[i]) == 0) {
|
|
|
|
if (getUndeliveredCount(packages[i]) == 0) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (map != null) {
|
|
|
|
if (map != null) {
|
|
|
|
map.updatePackageLayer(packages);
|
|
|
|
map.updatePackageLayer(packages);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPackageList();
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
// It'll show up sooner or later anyways
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadPackageList();
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
|
|
|
// It'll show up sooner or later anyways
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playSound("alert");
|
|
|
|
playSound("alert");
|
|
|
|
packages[i].lastAlert = currentTimestamp;
|
|
|
|
packages[i].lastAlert = currentTimestamp;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
|
|
|
map.startLocateControl();
|
|
|
|
|
|
|
|
mapLocationControlStarted = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}, function (err) {
|
|
|
|
if (map != null) {
|
|
|
|
if (typeof error == "function") {
|
|
|
|
map.startLocateControl();
|
|
|
|
error(err.message);
|
|
|
|
mapLocationControlStarted = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
}, function (err) {
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
if (typeof error == "function") {
|
|
|
|
timeout: 5000,
|
|
|
|
error(err.message);
|
|
|
|
maximumAge: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
}, {
|
|
|
|
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
|
|
|
|
timeout: 5000,
|
|
|
|
|
|
|
|
maximumAge: 0
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
geoerrorcount++;
|
|
|
|
|
|
|
|
console.log("Warn", "Geolocation error #" + geoerrorcount + ": ", error);
|
|
|
|
|
|
|
|
// Stop showing error toasts if they're happening a lot
|
|
|
|
|
|
|
|
if (geoerrorcount <= 3) {
|
|
|
|
|
|
|
|
app.toast.show({
|
|
|
|
|
|
|
|
text: '<i class="fas fa-compass"></i> ' + error,
|
|
|
|
|
|
|
|
position: "bottom",
|
|
|
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
|
|
|
closeTimeout: 1000 * 3
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
geoerrorcount++;
|
|
|
|
|
|
|
|
console.log("Warn", "Geolocation error #" + geoerrorcount + ": ", error);
|
|
|
|
|
|
|
|
// Stop showing error toasts if they're happening a lot
|
|
|
|
|
|
|
|
if (geoerrorcount <= 3) {
|
|
|
|
|
|
|
|
app.toast.show({
|
|
|
|
|
|
|
|
text: '<i class="fas fa-compass"></i> ' + error,
|
|
|
|
|
|
|
|
position: "bottom",
|
|
|
|
|
|
|
|
destroyOnClose: true,
|
|
|
|
|
|
|
|
closeTimeout: 1000 * 3
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|