我写了一个混合应用程序。我使用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未定义