【发布时间】:2016-07-09 02:22:35
【问题描述】:
我在 Ionic App 中通过 Google 地图进行 GPS 检测时遇到问题。当我在关闭 GPS 的情况下启动应用程序,然后我从设置设备更改为打开 GPS,单击 Find Me 按钮 - centerOnMe() 功能 - 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
}
);
});
};
【问题讨论】:
标签: ionic-framework gps geolocation