У меня написано гибридное приложение. Я использую плагин cordova для определения местоположения. Я получаю сообщение об ошибке при вызове AlarmOn ();через setTimeout. Вот мой код:
else if (response.status === "Tega201") {
ons.notification.alert(response.message);
const navigator = document.querySelector('#navigator');
navigator.resetToPage('teguaPage.html');
var tega_end_time = response.tega_end_time;
var deadline = new Date(tega_end_time).getTime();
const alarmON = () =>{
function getPosition() {
var options = {
enableHighAccuracy: true,
maximumAge: 3600000
}
var watchID = navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
function onSuccess(position) {
var longitude = String(position.coords.longitude);
var latitude = String(position.coords.latitude);
var phone_number = String(storage.getItem('phone_number'));
var submitAlarmOnLocation = {
"async": true,
"crossDomain": true,
"url": serverUrl + 'alarm_on_location_reporting/',
"method": "POST",
"headers": {
"Accept": "*/*",
"Content-Type": "application/json; charset=UTF-8",
},
"processData": false,
"data": "{\n\t\"phone_number\": \"" + phone_number + "\",\n\t\"latitude\":\"" + latitude + "\",\n\t\"longitude\":\"" + longitude + "\"\n}"
}
$.ajax(submitAlarmOnLocation).done(function(response){
ons.notification.alert(response);
});
};
function onError(error) {
ons.notification.alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
}
}
getPosition();
}
var x = setInterval(function() {
var now = new Date().getTime();
var t = deadline - now;
var days = Math.floor(t / (1000 * 60 * 60 * 24));
var hours = Math.floor((t%(1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((t % (1000 * 60)) / 1000);
if (t < 0) {
console.log("Now pull geolocation" +tega_end_time+ "");
alarmON();
clearInterval(x);
}
}, 1000);
}
Что может быть не так? Пожалуйста, помогите .. Я получаю сообщение об ошибке, что getCurrentPosition не определено