怎么定义多个位置位置数据?
发布于 6 年前 作者 gang52 2900 次浏览 来自 问答
多少位置数据怎么写入data,求指点。

Page({
  data: {
    location:[],
    location1:[],
        location2:[]
        location3:[]
        location4:[]
        location5:[]

  },
onLoadfunction() {
  var _this = this;
  _this.findXy() //查询用户与商家的距离
  },
  findXy() { //获取用户的经纬度
  var _this = this
  var _thiss = this
  wx.getLocation({
  type'wgs84',
  success(res) {
  _this.getDistance(res.latitude, res.longitude, 23.287080,113.822823,)
  _this.getDistance(res.latitude, res.longitude, 124.287080,113.822823)
  _this.getDistance(res.latitude, res.longitude, 125.287080,113.822823)
  _this.getDistance(res.latitude, res.longitude, 126.287080,113.822823)
  _this.getDistance(res.latitude, res.longitude, 127.287080,113.822823)
  _thiss.getDistance(res.latitude, res.longitude, 128.287080,113.822823)
  _this.getDistance(res.latitude, res.longitude, 129.287080,113.822823)
  }
  })
  },
  Radfunction(d//根据经纬度判断距离
  return d * Math.PI / 180.0;
  },
  getDistancefunction(lat1, lng1, lat2, lng2{
  // lat1用户的纬度
  // lng1用户的经度
  // lat2商家的纬度
  // lng2商家的经度
var radLat1 = this.Rad(lat1);
var radLat2 = this.Rad(lat2);
var a = radLat1 - radLat2;
var b = this.Rad(lng1) - this.Rad(lng2);
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)));
s = s * 6378.137;
s = Math.round(s * 10000) / 10000;
s = s.toFixed(2) + '公里' //保留两位小数
console.log('经纬度计算的距离:' + s)
this.setData({
  location:s
    location1:s
    location2:s
    location3:s
    location4:s
    location5:s
})
return s
}
})


回到顶部