async judgeUserPermission() {
// #ifdef APP-PLUS
if (uni.getSystemInfoSync().platform == 'android') {
	return await new Promise((resolve, reject) => {
		var context = plus.android.importClass("android.content.Context");
		var locationManager = plus.android.importClass("android.location.LocationManager");
		var main = plus.android.runtimeMainActivity();
		var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
		if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
			uni.showModal({
				title: '提示',
				content: '请打开定位服务功能,并检查您的权限设定',
				showCancel: false,
				success(res) {
					if (res.confirm) {
						uni.hideLoading()
						var Intent = plus.android.importClass("android.content.Intent");
						var Settings = plus.android.importClass("android.provider.Settings");
						var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
						main.startActivity(intent); //打开系统设置GPS服务页面
					}
				}
			})
		} else {
			console.log('GPS已开启');
			resolve()
		}
	})
} else if (uni.getSystemInfoSync().platform == 'ios') {
	return await new Promise((resolve, reject) => {
		var cllocationManger = plus.ios.import("CLLocationManager");
		var enable = cllocationManger.locationServicesEnabled();
		var status = cllocationManger.authorizationStatus();
		if (enable && status != 2) {
			console.log("手机系统的定位已经打开");
			resolve()
		} else {
			console.log("手机系统的定位没有打开");
			uni.hideLoading()
			plus.nativeUI.confirm("定位权限没有开启,是否去开启?", function(e) {
				if (e.index == 0) {
					var UIApplication = plus.ios.import("UIApplication");
					var application2 = UIApplication.sharedApplication();
					var NSURL2 = plus.ios.import("NSURL");
					var setting2 = NSURL2.URLWithString("app-settings:");
					application2.openURL(setting2);

					plus.ios.deleteObject(setting2);
					plus.ios.deleteObject(NSURL2);
					plus.ios.deleteObject(application2);
				}
			}, {
				"buttons": ["去开启", "暂不开启"],
				"verticalAlign": "center"
			});
			// reject()
		}
		plus.ios.deleteObject(cllocationManger);
	})
}
// #endif
// #ifndef APP-PLUS
return await new Promise((resolve, reject) => {
	resolve()
})
// #endif
}

在调用定位方法前

this.judgeIOS().then(() => {	
	uni.getLocation({
		type: 'gcj02',
		success: (result) => {
			//
		})
	})
})
.catch( () => {
	console.log(err)
})
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐