161 lines
4.2 KiB
Vue
161 lines
4.2 KiB
Vue
<template>
|
|
<view class="uni-container">
|
|
<button @click="func1">获取权限</button>
|
|
<button @click="func2">注册隐私协议</button>
|
|
<button @click="func3">注册APPkey</button>
|
|
<button @click="func4">传入目的地地址直接导航到目的地</button>
|
|
|
|
<button @click="func5">传入起始地和目的地</button>
|
|
</view>
|
|
</template>
|
|
<script>
|
|
// TODO 修复Android v3 加载过慢问题
|
|
// #ifdef APP-PLUS
|
|
var domModule = weex.requireModule("dom");
|
|
domModule.addRule("fontFace", {
|
|
fontFamily: "uniicons",
|
|
src: "url('/static/uni.ttf')",
|
|
});
|
|
// #endif
|
|
export default {
|
|
props: {
|
|
hasLeftWin: {
|
|
type: Boolean,
|
|
},
|
|
leftWinActive: {
|
|
type: String,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
list: [],
|
|
};
|
|
},
|
|
methods: {
|
|
func1() {
|
|
// 检查是否已经授权
|
|
const context = plus.android.runtimeMainActivity();
|
|
const PackageManager = plus.android.importClass(
|
|
"android.content.pm.PackageManager"
|
|
);
|
|
const hasPermission =
|
|
context.checkCallingOrSelfPermission(
|
|
"android.permission.ACCESS_FINE_LOCATION"
|
|
) === PackageManager.PERMISSION_GRANTED;
|
|
|
|
// true 的时候 就是有了位置权限
|
|
if (hasPermission) {
|
|
let seatInfo = uni.getStorageSync("seatInfo");
|
|
if (seatInfo) {
|
|
return JSON.parse(seatInfo);
|
|
} else {
|
|
plus.geolocation.getCurrentPosition(async function (position) {
|
|
console.log("当前位置:", position);
|
|
let res = position.coords;
|
|
let seatInfo = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
};
|
|
uni.setStorageSync("seatInfo", JSON.stringify(seatInfo));
|
|
uni.setStorageSync("actualLocation", JSON.stringify(seatInfo));
|
|
_this.seat = seatInfo;
|
|
let latitude = res.latitude;
|
|
let longitude = res.longitude;
|
|
return {
|
|
latitude: latitude,
|
|
longitude: longitude,
|
|
};
|
|
});
|
|
}
|
|
} else {
|
|
uni.showModal({
|
|
title: "注意",
|
|
content:
|
|
"拒绝授权位置服务会导致小程序功能无法正常使用,建议授权位置信息",
|
|
confirmText: "去设置",
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
const main = plus.android.runtimeMainActivity();
|
|
const Intent = plus.android.importClass("android.content.Intent");
|
|
const Settings = plus.android.importClass(
|
|
"android.provider.Settings"
|
|
);
|
|
const intent = new Intent(
|
|
Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
|
);
|
|
const uri = plus.android.invoke(
|
|
"android.net.Uri",
|
|
"parse",
|
|
"package:" + main.getPackageName()
|
|
);
|
|
intent.setData(uri);
|
|
main.startActivity(intent);
|
|
uni.switchTab({
|
|
url: "/pages/home/index",
|
|
});
|
|
}
|
|
},
|
|
});
|
|
}
|
|
},
|
|
func2() {
|
|
const addModule = uni.requireNativePlugin("AMapModule");
|
|
addModule.auth(
|
|
"692fb313cabed1578321a0f2d7ad74aa",
|
|
(suc) => {
|
|
console.log(suc);
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
},
|
|
func3() {
|
|
const addModule = uni.requireNativePlugin("AMapModule");
|
|
addModule.reg(
|
|
(suc) => {
|
|
console.log(suc);
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
},
|
|
func4() {
|
|
const addModule = uni.requireNativePlugin("AMapModule");
|
|
addModule.nav(
|
|
39.917337,
|
|
116.397056,
|
|
"博物院",
|
|
(suc) => {
|
|
console.log(suc);
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
},
|
|
func5() {
|
|
const addModule = uni.requireNativePlugin("AMapModule");
|
|
addModule.navfrom(
|
|
39.904556,
|
|
116.427231,
|
|
"火车站",
|
|
39.917337,
|
|
116.397056,
|
|
"博物院",
|
|
(suc) => {
|
|
console.log(suc);
|
|
},
|
|
(err) => {
|
|
console.log(err);
|
|
}
|
|
);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|