wx.getLocation({//自己的经纬度type:'wgs84',success:function(res){varlatituderes.latitude;//纬度varlongituderes.longitude;//经度}})1.

onLoad:function(options){

2.

this.distance(la1,lo1,la2,lo2);//二者之间的距离

3.

//修改distance这里面的四个参数la1为a地点的纬度,lo1为a地点的纬度,la2为b地点的纬度,lo2为b地点的纬度

4.

}

5.

distance:function(la1,lo1,la2,lo2){//计算距离km

6.

varLa1la1*Math.PI/180.0;

7.

varLa2la2*Math.PI/180.0;

8.

varLa3La1-La2;

9.

varLb3lo1*Math.PI/180.0-lo2*Math.PI/180.0;

10.

vars2*Math.asin(Math.sqrt(Math.pow(Math.sin(La3/2),2)+Math.cos(La1)*Math.cos(La2)*Math.pow(Math.sin(Lb3/2),2)));

11.

ss*6378.137;//地球半径

12.

sMath.round(s*10000)/10000;

13.

returns

14.

//console.log("计算结果:"+s+"km");

15.

},

TAG标签: 微信小程序计算二者之间的距离直线微信有没有测量距离的小程序微信小程序ibeacon

http://www.xiaochengxub.com/read-96247.html