当前位置:网站首页>Wechat applet calculates the distance between the two places
Wechat applet calculates the distance between the two places
2022-07-02 04:04:00 【Minced pork, pumpkin and scallop】
// Packaging function Calculated distance
distance: function (la1, lo1, la2, lo2) {
var La1 = la1 * Math.PI / 180.0;
var La2 = la2 * Math.PI / 180.0;
var La3 = La1 - La2;
var Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
var s = 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;
s = s.toFixed(2);
return s;
},// Send a request to query the longitude and latitude of the destination Get current location Usage method
onLoad: function (options) {
let _this = this
let id = options.id;
wx.request({
url: 'http://www.week.com/index.php/msg',
data:{id:id},
success(e){
let data = e.data.data;
let latitude= e.data.data.latitude;
let longitude=e.data.data.longitude;
wx.getLocation({
success(e){
let la = e.latitude
let lo = e.longitude
let distance = _this.distance(la,lo,latitude,longitude)
_this.setData({distance})
}
})
_this.setData({data,latitude,longitude})
}
})
}边栏推荐
猜你喜欢

跳出舒适区,5年点工转型自动化测试工程师,我只用了3个月时间

Force buckle 540 A single element in an ordered array

The 10th Blue Bridge Cup single chip microcomputer provincial competition

Opencv learning example code 3.2.4 LUT

Yyds dry inventory compiler and compiler tools

【小技巧】使用matlab GUI以对话框模式读取文件

Flutter中深入了解MaterialApp,常用属性解析

手撕——排序

Use of go package

2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
随机推荐
Didi open source Delta: AI developers can easily train natural language models
Basic operations of MySQL database (based on tables)
66.qt quick QML Custom Calendar component (supports vertical and horizontal screens)
2022-07-01: at the annual meeting of a company, everyone is going to play a game of giving bonuses. There are a total of N employees. Each employee has construction points and trouble points. They nee
Typescript practice for SAP ui5
The 7th Blue Bridge Cup single chip microcomputer provincial competition
[live broadcast review] the first 8 live broadcasts of battle code Pioneer have come to a perfect end. Please look forward to the next one!
[untitled]
Installation et utilisation du lac bleu
[untitled]
Go branch and loop
Interface debugging tool simulates post upload file - apipost
【无线图传】基于FPGA的简易无线图像传输系统verilog开发,matlab辅助验证
0 foundation how to learn automated testing? Follow these seven steps step by step and you will succeed
Use of go package
The first game of the 11th provincial single chip microcomputer competition of the Blue Bridge Cup
The 9th Blue Bridge Cup single chip microcomputer provincial competition
Visual slam Lecture 3 -- Lie groups and Lie Algebras
Flutter中深入了解MaterialApp,常用属性解析
潘多拉 IOT 开发板学习(RT-Thread)—— 实验1 LED 闪烁实验(学习笔记)