var permissions = cordova.plugins.permissions;
permissions.hasPermission(permissions.ACCESS_COARSE_LOCATION, checkPermissionCallback, null);
function checkPermissionCallback(status) {
console.log("first"+status.hasPermission); ----FALSE
if(!status.hasPermission) {
var errorCallback = function() {
console.warn('ACCESS_COARSE_LOCATION permission is not turned on');
};
permissions.requestPermission(
permissions.ACCESS_COARSE_LOCATION,
function(status) {
console.log("second"+status.hasPermission); ----TRUE
if(!status.hasPermission) errorCallback();
},
errorCallback);
}
}
在controller里面
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation.getCurrentPosition(posOptions).then(function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
console.log(latitude);
console.log(longitude);
}, function(err) {
console.log(err);
});
android6.0 动态设置允许访问位置权限了 (在低版本的android机上可以正常获取经纬度)
使用 $cordovaGeolocation.getCurrentPosition 插件的时候 仍然报这个错误 object PositionError,实在不知道为什么会这样,求大神帮忙,谢谢
02-10 14:13:18.356: I/SendBroadcastPermission(973): action:android.location.LOCATION_REQUEST_CHANGE_ACTION, mPermissionType:0
02-10 14:13:18.356: I/LocationManagerService(973): provider request: fused ProviderRequest[OFF]
02-10 14:13:18.357: I/LocationManagerService(973): provider request: local_database ProviderRequest[ON interval=0]
02-10 14:13:18.357: I/LocationManagerService(973): remove edb07e7
02-10 14:13:18.357: E/HwReportTool(973): This is not beta user build
02-10 14:13:18.357: I/SendBroadcastPermission(973): action:android.location.LOCATION_REQUEST_CHANGE_ACTION, mPermissionType:0
02-10 14:13:18.357: I/chromium(9740): [INFO:CONSOLE(207)] "[object PositionError]", source: file:///android_asset/www/js/controllers.js (207)
02-10 14:13:18.357: I/LocationManagerService(973): provider request: local_database ProviderRequest[ON interval=0]
02-10 14:13:18.608: E/WifiConfigStore(973): updateConfiguration freq=2412 BSSID=ec:88:8f:44:d4:7e RSSI=-65 "guangming"WPA_PSK
1 个解决方案
#1
platforms/android/AndroidManifest.xml中android:targetSdkVersion的值修改成22可以跳过Android6.0权限申请的问题
#1
platforms/android/AndroidManifest.xml中android:targetSdkVersion的值修改成22可以跳过Android6.0权限申请的问题