当前位置:网站首页>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})
}
})
}
边栏推荐
- Handling of inconsistency between cursor and hinttext position in shutter textfield
- The 7th Blue Bridge Cup single chip microcomputer provincial competition
- 滴滴开源DELTA:AI开发者可轻松训练自然语言模型
- Wechat applet - realize the countdown of 60 seconds to obtain the mobile verification code (mobile number + verification code login function)
- 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
- 【leetcode】74. Search 2D matrix
- Go language naming specification
- 如何解决在editor模式下 无法删除物体的问题
- How much is the tuition fee of SCM training class? How long is the study time?
- Document declaration and character encoding
猜你喜欢
文档声明与字符编码
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
《动手学深度学习》(二)-- 多层感知机
The 11th Blue Bridge Cup single chip microcomputer provincial competition
Spring recruitment of Internet enterprises: Kwai meituan has expanded the most, and the annual salary of technical posts is up to nearly 400000
Didi open source Delta: AI developers can easily train natural language models
Delete the code you wrote? Sentenced to 10 months!
2022-07-01:某公司年会上,大家要玩一食发奖金游戏,一共有n个员工, 每个员工都有建设积分和捣乱积分, 他们需要排成一队,在队伍最前面的一定是老板,老板也有建设积分和捣乱积分, 排好队后,所有
Use a mask to restrict the input of the qlineedit control
Basic operations of MySQL database (based on tables)
随机推荐
Which insurance company has a better product of anti-cancer insurance?
How about Ping An lifetime cancer insurance?
JVM knowledge points
regular expression
What is 5g industrial wireless gateway? What functions can 5g industrial wireless gateway achieve?
Sword finger offer II 006 Sort the sum of two numbers in the array
【leetcode】74. Search 2D matrix
Which is better, industrial intelligent gateway or edge computing gateway? How to choose the right one?
[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!
A thorough understanding of the development of scorecards - the determination of Y (Vintage analysis, rolling rate analysis, etc.)
【leetcode】81. Search rotation sort array II
Go branch and loop
go 语言命名规范
pip 安装第三方库
How to solve the problem that objects cannot be deleted in Editor Mode
《动手学深度学习》(二)-- 多层感知机
Blue Bridge Cup SCM digital tube skills
手撕——排序
文档声明与字符编码
Fingertips life Chapter 4 modules and packages