index.js
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// pages/crowdfunding/components/navigation/index.js
import {
iosTimeFormat
} from '~/utils/format'
Component({
/**
* 组件的属性列表
*/
properties: {
detail: {
type: Object,
value: {},
observer: function (o) {
this.init(o)
}
}
},
/**
* 组件的初始数据
*/
data: {
addressInfo: {}
},
/**
* 组件的方法列表
*/
methods: {
// 初始化
init(data) {
console.log(data)
if (!data.startTime) {
return false
}
data.s_time = new Date(iosTimeFormat(data.startTime)).format('yyyy年M月d日')
data.e_time = new Date(iosTimeFormat(data.endTime)).format('yyyy年M月d日')
this.setData({
addressInfo: data
})
},
// // 兼容ios时间
// iosTimeFormat(time) {
// if (!time) {
// return ''
// }
// return time.replace(/-/g, '/')
// },
// 获取地址
getLocation() {
const appEnter = wx.getEnterOptionsSync()
if (appEnter.scene === 1154) {
wx.$eventbus.emit('showTimeLineToast')
return
}
let _this = this
let o = _this.data.addressInfo
if (o.distance) {
wx.openLocation({
latitude: o.activityAddressLat,
longitude: o.activityAddressLng
})
return false
}
if (!o.activityAddressLat || !o.activityAddressLng) {
return false;
}
wx.getLocation({
type: 'gcj02',
success: function (res) {
console.log(res)
let distance = _this.getDistance(o.activityAddressLat, o.activityAddressLng, res.latitude, res.longitude)
console.log(distance)
o.distance = (distance / 1000).toFixed(2)
_this.setData({
addressInfo: o
})
}
})
},
// 计算两个gps点之间距离
getDistance(latFrom, lngFrom, latTo, lngTo) {
var EARTH_RADIUS = 6378136.49
function rad(d) {
return (d * Math.PI) / 180.0
}
var radLatFrom = rad(latFrom)
var radLatTo = rad(latTo)
var a = radLatFrom - radLatTo
var b = rad(lngFrom) - rad(lngTo)
var distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2)))
distance = distance * EARTH_RADIUS
distance = Math.round(distance * 10000) / 10000
return parseFloat(distance.toFixed(0))
}
}
})