在 Android(HTC Incredible S 设备和 Android 虚拟设备)上,当我导航到“我在哪里?”时 页:
- 初始化并显示繁忙指示器“正在检查您的位置”
- 加载谷歌地图API
- 地理位置和显示谷歌地图
- 隐藏忙碌指示器
我第一次进入该页面时,从未显示忙碌指示符。
我第二次进入该页面时,有一个“加载”繁忙指示器冻结了我的应用程序。我必须杀死应用程序外的进程。
当我删除繁忙指示器的代码行时,我的应用程序运行正常。
这是繁忙指示器冻结的代码:
// 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');
}
}