2013-06-27 97 views
0

在Android(HTC Incredible S設備和Android虛擬設備)上,當我導航到我的「我在哪裏?」頁:worklight v6.0繁忙指標問題與Android

  1. init和顯示繁忙指示「檢查你的位置」
  2. 負荷谷歌地圖API
  3. 地理定位和顯示谷歌地圖
  4. 隱藏的忙指示

我第一次去到那個頁面,忙指示符從不顯示。

第二次我去那個頁面,有一個「加載」繁忙指標凍結我的應用程序。我必須殺死應用程序之外的進程。

當我刪除忙線指示燈的代碼行時,我的應用程序工作正常。

這裏有繁忙指示凍結代碼:

// Geolocation of collaborators 
var map; 
function initialize() { 
    var busyInd = new WL.BusyIndicator('content', {text : 'Checking your location...'}); 
    busyInd.show(); 
    console.log('Initializing google Maps'); 

     // Try HTML5 geolocation 
    if(navigator.geolocation) { 
     var options = { timeout: 30000, enableHighAccuracy: true }; 

     navigator.geolocation.getCurrentPosition(function(position) { 
     var mapOptions = { 
         zoom: 6, 
         streetViewControl: false, 
         mapTypeControl: false, 
         mapTypeId: google.maps.MapTypeId.ROADMAP 
        }; 
     map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions); 

     var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
     var infowindow = new google.maps.InfoWindow({ 
      map: map, 
      position: pos, 
      content: 'You are here', 
      maxWidth: 60 
     }); 
     map.setCenter(pos); 
     }, function(error) { 
      console.log('Hiding busy indicator when geolocation failed'); 
    busyInd.hide(); 
     handleNoGeowith location(true, error); 
     }, options); 
    } else { 
     // Browser doesn't support Geolocation 
     handleNoGeolocation(false); 
     busyInd.hide(); 
    } 
busyInd.hide(); 
} 

function handleNoGeolocation(errorFlag, error) { 
    console.log('Handle no geolocation message error'); 
var content; 
if (errorFlag) { 
    var errorCode = error.code; 
    var errorMsg = error.message; 
    content = 'Error: The Geolocation service failed. Code: '+errorCode+', Message: '+errorMsg; 
} else { 
    content = 'Error: Your browser doesn\'t support geolocation.'; 
} 

alert(content); 
} 
var isGMapAPILoaded = false; 
function loadGoogleMaps() { 
    console.log('initializing google maps api'); 
    if(isGMapAPILoaded){ 
     // Google Maps API already loaded 
     console.log('Google Maps API already loaded, call initialize'); 
     initialize(); 
    } else { 
     var script = document.createElement("script"); 
     script.type = "text/javascript"; 
     script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize"; 
     document.body.appendChild(script); 
     isGMapAPILoaded = true; 
     console.log('Google Maps API loaded with success'); 
    } 
} 

回答

0

您是否嘗試過在全球創建的忙指示對象,而不是此特定函數內(我也不懂這個「初始化」功能的範圍...我認爲這是特定於應用程序的代碼)。

在您的應用程序的.js文件(yourProject \ APPS \ yourApp \ COMMON \ yourApp.js)做這樣的事情:

var busy; 

function wlCommonInit() { 

    busy = new WL.BusyIndicator(); 

然後,在你initialize()功能,在需要時調用busy.show()busy.hide()