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
}
);
});
};