【发布时间】:2015-10-20 12:14:21
【问题描述】:
我有这个问题,我有 4 个变量要用 GPS 坐标初始化,一旦加载,我必须进入另一个脚本。 前 2 个立即加载,另外 2 个在 4 秒后加载,如下所示:
(function(){
function onSuccess(position) {
poslat = position.coords.latitude;
poslon = position.coords.longitude;
console.log('latitudine1 ' + poslat);
console.log('longitudine1 ' + poslon);
//after 4 second
setTimeout(function(){
poslt = position.coords.latitude;
posln = position.coords.longitude;
speed = position.coords.speed;
alt = position.coords.altitudeAccuracy;
precisione = position.coords.accuracy;
document.getElementById("altitudine").innerHTML = alt;
document.getElementById("precision").innerHTML = precisione;
var speedfix = speed * 3.6;
var speedfixed = speedfix.toFixed(3);
document.getElementById("sped").innerHTML = speedfixed;
console.log('latitudine2 ' + poslt);
console.log('longitudine2 ' + posln);
//alert("Passed 4 second");
},4000);
如果您知道如何为此创建条件“if”(例如:当所有坐标变量都初始化时,执行此操作)?因为 GPS 总是加载不同的时间并且速度很慢 谢谢。
这样,我试过了
if (poslat != null || poslon != null || poslt != null || posln != null )
{
//code
}
【问题讨论】:
标签: javascript android variables gps coordinates