2023-08-18 16:03:25 +08:00

347 lines
6.4 KiB
Vue

<!-- -->
<template>
<view>
<button @click="test2">按钮</button>
{{a}}
<!-- <map id="map" @markertap='mapFun' :enable-zoom="true" :polyline="polyline" :markers='markers' :scale="scale"
style="width:100vw;height: 70vh;" :latitude="28.908447" :enable-scroll="true" :longitude="105.439304">
</map> -->
</view>
</view>
</template>
<script>
import {
getDetil
} from "@/api/logistics.js"
import {
takeGoods
} from "@/api/logistics.js"
var jpushModule = uni.requireNativePlugin("JG-JPush");
export default {
data() {
return {
a: "暂无",
flag: 0,
showLoading: true,
showPop: false,
goodsDetil: undefined,
scale: 15,
nowAddress: "无",
arr: [
{
latitude: 28.916022,
longitude: 105.442732,
},
{
latitude: 28.916848,
longitude: 105.443175,
},
{
latitude: 28.916918,
longitude: 105.443269,
},
{
latitude: 28.917041,
longitude: 105.443466,
},
{
latitude: 28.917073,
longitude: 105.443522,
},
{
latitude: 28.91705,
longitude: 105.443607,
},
{
latitude: 28.917057,
longitude: 105.443643,
},
{
latitude: 28.916925,
longitude: 105.443546,
},
{
latitude: 28.916796,
longitude: 105.443466,
},
{
latitude: 28.916615,
longitude: 105.443344,
},
{
latitude: 28.916437,
longitude: 105.443274,
},
{
latitude: 28.916356,
longitude: 105.443222,
},
{
latitude: 28.916515,
longitude: 105.442643,
},
{
latitude: 28.916591,
longitude: 105.442448,
},
{
latitude: 28.916944,
longitude: 105.442338,
},
{
latitude: 28.91706,
longitude: 105.442376,
},
{
latitude: 28.917169,
longitude: 105.442489,
},
{
latitude: 28.917345,
longitude: 105.442601,
},
{
latitude: 28.917433,
longitude: 105.442663,
},
{
latitude: 28.917461,
longitude: 105.442683,
},
{
latitude: 28.917461,
longitude: 105.442683,
},
{
latitude: 28.917518,
longitude: 105.442874,
},
{
latitude: 28.917537,
longitude: 105.443032,
},
{
latitude: 28.917537,
longitude: 105.443032,
},
{
latitude: 28.917497,
longitude: 105.443198,
},
{
latitude: 28.917409,
longitude: 105.443256,
},
{
latitude: 28.91732,
longitude: 105.443318,
},
{
latitude: 28.917234,
longitude: 105.443442,
},
{
latitude: 28.917072,
longitude: 105.443497,
},
{
latitude: 28.916977,
longitude: 105.443539,
},
{
latitude: 28.916867,
longitude: 105.443529,
},
{
latitude: 28.916867,
longitude: 105.443529,
},
{
latitude: 28.916761,
longitude: 105.443404,
},
{
latitude: 28.916722,
longitude: 105.443274,
},
{
latitude: 28.916762,
longitude: 105.443132,
},
],
markers: [
// 商家
{
// 105.439304,28.908447
id: 1,
latitude: 28.916022,
longitude: 105.442732,
iconPath: '../../static/img/logistics/QS.png', //显示的图标
width: 30,
height: 30,
},
// 骑手
{
id: 2,
latitude: 28.916762,
longitude: 105.443132,
iconPath: '../../static/img/logistics/SJ.png',
width: 20,
height: 20, //显示的图标
}
],
polyline: [{ //初始值
name: 'Track 1',
arrowLine: true,
color: '#27bd09e6',
width: 8,
id: 1,
points: [],
},
]
}
},
methods: {
test2() {
// #ifdef APP-PLUS
jpushModule.getRegistrationID(result => {
let registerID = result.registerID
console.log("设备----", result)
})
// #endif
},
test() {
let i = 0
let timer = setInterval(() => {
this.markers[0].latitude = this.arr[i].latitude
this.markers[0].longitude = this.arr[i].longitude
i++
console.log(i)
// this.polyline[0].points.push(this.arr[i])
this.$set(this.polyline[0].points, i, this.arr[i])
if (i >= this.arr.length) {
console.log(this.polyline[0].points)
clearInterval(timer)
}
}, 50)
},
// 获取位置
// 位置
locationFn() {
let that = this
uni.getLocation({
type: 'wgs84',
geocode: true,
isHighAccuracy: true,
success: function async (res) {
that.markers[1].latitude = res.latitude
that.markers[1].longitude = res.longitude
that.getDriverLine()
}
});
},
getDriverLine() {
const that = this;
const key = "997c9a3d88154fa78f4d28bebc1dd84f";
const origin = `${this.markers[1].longitude},${this.markers[1].latitude}`;
const destination = `${this.markers[0].longitude},${this.markers[0].latitude}`;
console.log(that.markers)
uni.request({
// url: `https://restapi.amap.com/v3/direction/walking?key=${key}&origin=105.43639400000002,28.908854&destination=105.439304,28.908447`,
url: `https:restapi.amap.com/v4/direction/bicycling?key=${key}&origin=${origin}&destination=${destination}`,
success: (res) => {
const data = res.data.data;
console.log(res.data)
var points = [];
if (data.paths && data.paths[0] && data.paths[0].steps) {
var steps = data.paths[0].steps;
for (var i = 0; i < steps.length; i++) {
//将每一步的数据放到points数组中
var poLen = steps[i].polyline.split(";");
for (var j = 0; j < poLen.length; j++) {
points.push({
longitude: parseFloat(poLen[j].split(",")[0]),
latitude: parseFloat(poLen[j].split(",")[1]),
});
}
}
that.runningRoute = data.paths[0].steps[0].instruction;
}
that.polyline = [{
points: points,
color: "#0091ff",
dottedLine: true,
width: 10,
}, ];
},
fail: function(res) {
console.log("获取路线失败", res);
},
});
},
},
onLoad() {
jpushModule.initJPushService()
console.log("初始化完成")
jpushModule.addConnectEventListener(result => {
let connectEnable = result.connectEnable //boolean
console.log("连接状态---", result)
})
// this.locationFn()
},
}
</script>