gpt4 book ai didi

javascript - 仅当初始化变量时,“IF”才是启动变量的条件

转载 作者:行者123 更新时间:2023-11-28 07:06:07 24 4
gpt4 key购买 nike

我有这个问题,我有 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
}

最佳答案

此代码适用于 wi-fi/3g 连接。

 if ((poslat != null) && (poslon != null) && (poslt != null) && (posln != null))
{
ready();
}else{
alert('GPS / Connessione debole.. ')

}

但是当我仅使用 GPS(没有信号的地方)尝试时,它不起作用。为什么 ?我认为当加载 GPS 时,变量没有值“null”但哪个??

关于javascript - 仅当初始化变量时,“IF”才是启动变量的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31701736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com