在Android(HTC Incredible S设备和Android虚拟设备)上,当我导航到我的“我在哪里?”页:
第一次进入该页面时,忙碌指示灯从不显示。
第二次进入该页面时,有一个“正在加载”忙碌指示器冻结我的应用程序。我必须杀死应用程序外的进程。
当我删除繁忙指示符的代码行时,我的应用程序正常运行。
以下是Busy Indicator冻结的代码:
// 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 :(得分:0)
你是否尝试过全局创建繁忙的指标对象而不是在这个特定的函数内部(我也不明白这个“初始化”函数的范围......我认为这是特定于应用程序的代码)。
在你的应用的.js文件(yourProject \ apps \ yourApp \ common \ yourApp.js)中执行以下操作:
var busy;
function wlCommonInit() {
busy = new WL.BusyIndicator();
然后,在您的initialize()
功能中,在需要时致电busy.show()
和busy.hide()
。