|
@@ -1,6 +1,8 @@
|
1
|
1
|
//index.js
|
2
|
2
|
//获取应用实例
|
3
|
3
|
const app = getApp()
|
|
4
|
+const HttpSever = require('../../../utils/http.js').HttpSever;
|
|
5
|
+const $api = require('../../../config/api.js').$api;
|
4
|
6
|
|
5
|
7
|
Component({
|
6
|
8
|
behaviors: [],
|
|
@@ -28,7 +30,23 @@ Component({
|
28
|
30
|
}]
|
29
|
31
|
},
|
30
|
32
|
lifetimes: {},
|
31
|
|
- ready: function() {},
|
|
33
|
+ ready: function() {
|
|
34
|
+ const _that = this
|
|
35
|
+ wx.getSetting({
|
|
36
|
+ success(res) {
|
|
37
|
+ if (!res.authSetting['scope.userLocation']) {
|
|
38
|
+ wx.authorize({
|
|
39
|
+ scope: 'scope.userLocation',
|
|
40
|
+ success() {
|
|
41
|
+ _that.ShowLocation()
|
|
42
|
+ }
|
|
43
|
+ })
|
|
44
|
+ } else {
|
|
45
|
+ _that.ShowLocation()
|
|
46
|
+ }
|
|
47
|
+ }
|
|
48
|
+ })
|
|
49
|
+ },
|
32
|
50
|
pageLifetimes: {
|
33
|
51
|
show: function() {},
|
34
|
52
|
},
|
|
@@ -37,6 +55,49 @@ Component({
|
37
|
55
|
wx.navigateTo({
|
38
|
56
|
url: '/pages/EstateDetail/index?id='
|
39
|
57
|
})
|
|
58
|
+ },
|
|
59
|
+ GetGreatCircleDistance(lat1, lng1, lat2, lng2) {
|
|
60
|
+ if (lat1 === lat2 && lng1 === lng2) {
|
|
61
|
+ return 0
|
|
62
|
+ }
|
|
63
|
+ var EARTH_RADIUS = 6378137.0//单位M
|
|
64
|
+ var PI = Math.PI
|
|
65
|
+ var radLat1 = lat1 * PI / 180.0
|
|
66
|
+ var radLat2 = lat2 * PI / 180.0
|
|
67
|
+ var a = radLat1 - radLat2
|
|
68
|
+ var b = lng1 * PI / 180.0 - lng2 * PI / 180.0
|
|
69
|
+ var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
|
|
70
|
+ s = s * EARTH_RADIUS
|
|
71
|
+ s = Math.round(s * 10000) / 10000.0
|
|
72
|
+ console.log(s)
|
|
73
|
+ return s
|
|
74
|
+ },
|
|
75
|
+ ShowLocation() {
|
|
76
|
+ const _that = this
|
|
77
|
+ wx.getLocation({
|
|
78
|
+ type: 'wgs84',
|
|
79
|
+ success(res) {
|
|
80
|
+ console.log(res)
|
|
81
|
+ HttpSever.Ajax({
|
|
82
|
+ url: $api.building.list.url,
|
|
83
|
+ method: $api.building.list.method,
|
|
84
|
+ }).then((data) => {
|
|
85
|
+ const eslist = data.data.map(x => {
|
|
86
|
+ const distance = parseInt(_that.GetGreatCircleDistance(res.latitude, res.longitude, x.coordinate.split(',')[0], x.coordinate.split(',')[1] || res.longitude))
|
|
87
|
+ return {
|
|
88
|
+ buildingName: x.buildingName,
|
|
89
|
+ price: x.price,
|
|
90
|
+ address: x.address,
|
|
91
|
+ buildingImg: (x.buildingImg[0] || {}).url,
|
|
92
|
+ distance: distance / 1000
|
|
93
|
+ }
|
|
94
|
+ })
|
|
95
|
+ _that.setData({
|
|
96
|
+ EstateList: eslist
|
|
97
|
+ })
|
|
98
|
+ })
|
|
99
|
+ }
|
|
100
|
+ })
|
40
|
101
|
}
|
41
|
102
|
}
|
42
|
103
|
})
|