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");
}
});
请正确格式化您的代码。 –