1.登录高德地图/
a.创建新应用
这个key后边整合的时候会用到,精彩继续
b.下载SDK/api/wx/download
待会我们用的就是这个js文件
2. 到微信小程序中
a.新建wxs文件夹将amap-wx.js文件复制粘贴进去
b.使用:
代码:varamapFile=require('../../wxs/amap-wx.js');
c.获取定位以及计算两点经纬度距离单位(KM)
代码清单:
Page({
data:{
gaodeAddress:""//定位地址
},
//通过两点经纬度计算距离(KM)
distance:function(la1,lo1,la2,lo2){
varLa1=la1*Math.PI/180.0;
varLa2=la2*Math.PI/180.0;
varLa3=La1-La2;
varLb3=lo1*Math.PI/180.0-lo2*Math.PI/180.0;
vars=2*Math.asin(Math.sqrt(Math.pow(Math.sin(La3/2),2)+Math.cos(La1)*Math.cos(La2)*Math.pow(Math.sin(Lb3/2),2)));
s=s*6378.137;//地球半径
s=Math.round(s*10000)/10000;
console.log("计算结果",s);
returns;
},
//高德地图获取定位
gaodeGetLocation:function(){
varthat=this;
varmyAmapFun=newamapFile.AMapWX({key:'24736188d851d49921a02a6e0ccd79b8'});
myAmapFun.getRegeo({
success:(res)=>{
console.log("高德地图获取定位:"+JSON.stringify(res),res[0].regeocodeData.formatted_address);
//计算两个经纬度距离
varjl=that.distance(39.928712,116.393345,res[0].latitude,res[0].longitude);
console.log("打印计算两个点的距离:"+jl);
this.setData({
gaodeAddress:res[0].regeocodeData.formatted_address
})
}
})
}
.......