赞
踩
- export default {
- getPosition() {
- uni.showLoading({
- title: "获取定位中...",
- mask: true,
- });
- return new Promise((resolve, reject) => {
- uni.getLocation({
- type: 'gcj02',
- isHighAccuracy: true,
- success: (res) => {
- uni.hideLoading()
- resolve(res)
- },
- fail: (e) => {
- uni.hideLoading()
- reject(e)
- const { locationEnabled } = uni.getSystemSetting()//是否开启定位权限
- if (!locationEnabled) {
- uni.showModal({
- title: '提示',
- content: '获取定位失败,是否授权打开定位',
- success: (res) => {
- if (res.confirm) {
- uni.getSystemInfo({
- success: (sys) => {
- if (sys.platform == 'ios') {
- plus.runtime.openURL(
- "app-settings://");
- } else {
- const main = plus.android
- .runtimeMainActivity();
- const Intent = plus.android
- .importClass(
- "android.content.Intent"
- );
- //可能应该直接进入应用列表的权限设置?=> android.settings.APPLICATION_SETTINGS
- const mIntent = new Intent(
- 'android.settings.LOCATION_SOURCE_SETTINGS'
- );
- main.startActivity(mIntent);
- }
- }
- })
- }
- }
- })
- } else {
- uni.$u.toast('获取位置失败,请到空旷的地方试试!');
- }
-
- },
- });
- })
-
- },
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。