// 扩展API加载完毕后调用onPlusReady回调函数
document.addEventListener("plusready", onPlusReady, false);
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady() {
plus.geolocation.getCurrentPosition(function (position) {
}, function (e) {
var btnArray = [‘取消‘, ‘设置‘];
mui.confirm(‘您需要打开定位服务,才可以使用【呼归星球】。该位置信息用于在管理后台记录您的工作轨迹。请到设置->隐私->定位服务中开启。‘, ‘定位服务已关闭‘, btnArray, function (e) {
if (e.index == 1) {
if (mui.os.ios) {
var UIApplication = plus.ios.import("UIApplication");
var NSURL = plus.ios.import("NSURL");
var setting = NSURL.URLWithString("app-settings:");
var application = UIApplication.sharedApplication();
application.openURL(setting);
plus.ios.deleteObject(setting);
plus.ios.deleteObject(application);
} else {
var main = plus.android.runtimeMainActivity();
var Intent = plus.android.importClass("android.content.Intent");
var mIntent = new Intent(‘android.settings.LOCATION_SOURCE_SETTINGS‘);
main.startActivity(mIntent);
}
} else {
owner.doExitApp();
}
})
}, {
provider: ‘system‘, //system 表示系统定位模块 详情见:https://www.html5plus.org/doc/zh_cn/geolocation.html#plus.geolocation.PositionOptions
geocode: ‘true‘
})
}
原文借鉴于:https://blog.****.net/yxh1157686920/article/details/90240332