regionchange(e) {
if (e.type == ‘end’) {
console.log(“地图移动”)
this.getLngLat()
}
},
getLngLat: function () {
function sortNumber(a, b){
return a - b
}
var that = this;
this.mapCtx = wx.createMapContext(“myMap”);
this.mapCtx.getCenterLocation({
success: function (res) {
console.log(res);
that.setData({
centerLat: res.latitude,
centerLog: res.longitude,
})
console.log(“会重复调用”)
if (res.latitude == that.data.mapLat){
console.log(“相同”)
}else{
var setNum;
var grr = [];
for (var p = 0; p < that.data.circles.length; p++) {
var kun = p;
grr.push(calculateDistance(that.data.circles[kun].latitude, that.data.circles[kun].longitude, res.latitude, res.longitude))
}
grr.sort(sortNumber);
for (var p = 0; p < that.data.circles.length; p++) {
var kun = p;
if (grr[0] == calculateDistance(that.data.circles[kun].latitude, that.data.circles[kun].longitude, res.latitude, res.longitude)) {
console.log(“设置新的地图”)
setNum = kun; }
}
that.setData({
mapLat: that.data.circles[setNum].latitude,
mapLong: that.data.circles[setNum].longitude
})
}
}
})
},