|
@@ -56,7 +56,24 @@ Component({
|
56
|
56
|
url: '/pages/EstateDetail/index?id='
|
57
|
57
|
})
|
58
|
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
|
+ },
|
59
|
75
|
ShowLocation() {
|
|
76
|
+ const _that = this
|
60
|
77
|
wx.getLocation({
|
61
|
78
|
type: 'wgs84',
|
62
|
79
|
success(res) {
|
|
@@ -64,8 +81,20 @@ Component({
|
64
|
81
|
HttpSever.Ajax({
|
65
|
82
|
url: $api.building.list.url,
|
66
|
83
|
method: $api.building.list.method,
|
67
|
|
- }).then((date) => {
|
68
|
|
- console.log(date)
|
|
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
|
+ })
|
69
|
98
|
})
|
70
|
99
|
}
|
71
|
100
|
})
|