ionic 打开位置服务器,在IONIC中使用cordova-plugin-geolocation打开地理定位

如果正确理解您的问题,如果未启用GPS,则需要打开本机 gps 设置 .

您可以使用以下任何选项:

Using cordova-diagnostic-plugin plugin

isGpsLocationEnabled() diagnostic-plugin功能可以帮助您了解GPS是否启用 .

以下是用法:

cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled) {

if (enabled) {

//enabled

} else {

// open location native location settings

cordova.plugins.diagnostic.switchToLocationSettings();

}

},

function(error) {

console.error("The following error occurred: " + error);

});

Using request-location-accuracy plugin

如果位置精度插件的request()函数给你错误回调 . 在那里检查错误代码是否为ERROR_USER_DISAGREED,如果为true,则使用switchToLocationSettings() of cordova-diagnostic-plugin打开本机设置 .

以下是用法:

function onRequestSuccess(success) {

console.log("Successfully requested accuracy: " + success.message);

}

function onRequestFailure(error) {

console.error("Accuracy request failed: error code=" + error.code + "; error message=" + error.message);

if (error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED) {

if (window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")) {

// open location native location settings using diagnostic plugin

cordova.plugins.diagnostic.switchToLocationSettings();

}

}

}

cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值