0
我正在構建一個Android Ionic應用程序,該應用程序每次都使用cordova.geolocation.getCurrentPosition
GPS中斷,我無法獲取當前位置,因此它會移至錯誤功能。cordova.getCurrentLocation()方法無法正常工作
在較低版本的Android(5.0.0)中工作正常,但在較高版本(6.0.1及以上版本)中打破。
這裏是我的代碼:
var options = {
timeout: 10000,
maximumAge: 100,
enableHighAccuracy: false
};
$cordovaGeolocation.getCurrentPosition(options).then(function(position) {
$scope.UserCurrentLat = position.coords.latitude;
$scope.UserCurrentLng = position.coords.longitude;
var source = new google.maps.LatLng($scope.UserCurrentLat, $scope.UserCurrentLng);
var destination = new google.maps.LatLng(Data.data.geoLocation.coordinates[0], Data.data.geoLocation.coordinates[1]);
var directionsService = new google.maps.DirectionsService();
$scope.userRestDistance = parseFloat((google.maps.geometry.spherical.computeDistanceBetween(source, destination)/1000).toFixed(1))+" km";
$ionicLoading.hide();
}, function(error) {
$ionicLoading.hide();
if (error.PERMISSION_DENIED || error.POSITION_UNAVAILABLE) {
$ionicLoading.hide();
$location.path("/noGPS");
}
});
請正確格式化您的代碼。 –