1
我在Ionic App中的Google地图上检测到GPS时出现问题。当我用GPS关闭应用程序并稍后从“设置”设备更改为“GPS”时,单击“查找我”按钮 - centerOnMe()功能 - GPS不起作用。功能反应总是当我用GPS启动应用程序并关闭GPS后,GPS未被检测到位置
`Error: GPS Timeout! ERROR = 3`
在一开始,我认为这是一个缓存问题,但我发现不是这样。从视图中使用$ state.reload并不重要。 ¿有没有人得到同样的问题?感谢您的支持。我附上以下功能:
$scope.centerOnMe = function() {
$ionicPlatform.ready(function() {
console.log('Click on Find Me');
if(!map) {
return;
}
$ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
//$state.reload('app.map');
watchPositionId = navigator.geolocation.watchPosition(function(position) {
navigator.geolocation.clearWatch(watchPositionId);
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$scope.latitude = latitude;
$scope.longitude = longitude;
var geolocpoint = new google.maps.LatLng(latitude, longitude);
map.setCenter(geolocpoint);
});
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude
var long = position.coords.longitude
$scope.center = new google.maps.LatLng(lat, long);
$ionicLoading.hide();
console.log("GPS is enabled" + $scope.center);
}, function(err) {
// error
if (err.code == 1) { console.log('GPS disabled! ERROR = ' + err.code); }
else if(err.code == 2) { console.log('GPS is unavailable! ERROR = ' + err.code); }
else if(err.code == 3) { console.log('Error: GPS Timeout! ERROR = ' + err.code); }
$ionicLoading.hide();
}, {
enableHighAccuracy: true, timeout: 20000
}
);
});
};