flat: 添加地图

This commit is contained in:
Apcallover
2024-04-25 11:42:21 +08:00
parent 25f9e96a57
commit 3a5b9dd6cd
10 changed files with 487 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
function onDialingPhoneNumber(phone) {
export function onDialingPhoneNumber(phone) {
return new Promise((resolve, reject) => {
uni.makePhoneCall({
phoneNumber: phone, // 电话号码
@@ -11,8 +11,39 @@ function onDialingPhoneNumber(phone) {
});
})
}
/**
* 个位数加0前缀
* @param {*} number
* @returns
*/
export function addZeroPrefix(number) {
return number < 10 ? `0${number}` : number
}
export function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
const R = 6371; // 地球平均半径,单位为公里
const dLat = deg2rad(lat2 - lat1);
const dLon = deg2rad(lon2 - lon1);
const a =
Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
const d = R * c;
return {
km: d,
m: d * 1000
};
}
// 将角度转换为弧度
function deg2rad(deg) {
return deg * (Math.PI / 180);
}
export default {
onDialingPhoneNumber
onDialingPhoneNumber,
addZeroPrefix,
getDistanceFromLatLonInKm
}