getcoordinates: function (item) {
let this = this;
TDCommon.showLoading();
wx.getLocation({
type: "wgs84",
isHighAccuracy: true,
success(res) {
let latitude = res.latitude; //纬度
let longitude = res.longitude; //经度
console.log("微信经度:" + longitude);
console.log("微信纬度:" + latitude);
let url = "https://api.map.baidu.com/geoconv/v1/";
TDBaseNetWork.request({
url,
data: {
coords: ${longitude},${latitude}
,
from: 1,
to: 5,
ak: "BPGh4SkhpDWUnXnMAKE8PAwsONhEnw1v",
output: "json",
},
success: function (res) {
TDCommon.highlighting();
if (res.status != 0) {
TDCommon.toast(经纬度获取失败
);
return;
}
//经度
let lng = res.result[0].x;
//纬度
let lat = res.result[0].y;
let resultLongitude = new BigNumber(lng);
let resultLatitude = new BigNumber(lat);
let currentLongitude = resultLongitude
.dp(6, BigNumber.ROUND_DOWN)
.toString();
let currentLatitude = resultLatitude
.dp(6, BigNumber.ROUND_DOWN)
.toString();
let s = this.GetDistance(item.latitude, item.longitude, currentLatitude, currentLongitude);
console.log(经纬度之间的距离 ${s}
);
/因为s单位是km 所以这里要先换算成米 然后再进行比较大小 /
let numberBm = new BigNumber(s);
let numberBy = numberBm.multipliedBy(1000);
let result = numberBy.minus(300).toString();
console.log("比大小");
console.log(result);
if (result < 0) {
/说明已到达店铺位置 /
this.setData({
isPositionRange: true
});
}
console.log("百度经度:" + currentLongitude);
console.log("百度纬度:" + currentLatitude);
this.setData({
latitudeBaidu: currentLatitude,
longitudeBaidu: currentLongitude,
});
},
fail: function (err) {
TDCommon.highlighting();
console.log(err);
},
});
},
fail: function (err) {
TDCommon.highlighting();
console.log(err);
},
});
},