【问题标题】:'IF' Condition for start variable only if they are initialized'IF' 仅当它们被初始化时才用于开始变量的条件
【发布时间】: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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-06-03
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 2017-09-21
      • 1970-01-01
      • 2012-03-01
      • 2020-03-29
      相关资源
      最近更新 更多