廢話不多說,開整文章來源:http://www.zghlxwxcb.cn/news/detail-596121.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-596121.html
// 參數(shù)為寄件人經緯度和收件人經緯度
// 根據(jù)寄收件人經緯度弧度π進行rotate旋轉計算
const getRotate = (po1, po2) => {
if (!(po1 && po2)) return 0
const lng_a = po1.longitude
const lat_a = po1.latitude
const lng_b = po2.longitude
const lat_b = po2.latitude
const a = ((90 - lat_b) * Math.PI) / 180
const b = ((90 - lat_a) * Math.PI) / 180
const AOC_BOC = ((lng_b - lng_a) * Math.PI) / 180
const cosc = Math.cos(a) * Math.cos(b) + Math.sin(a) * Math.sin(b) * Math.cos(AOC_BOC)
const sinc = Math.sqrt(1 - cosc * cosc)
const sinA = (Math.sin(a) * Math.sin(AOC_BOC)) / sinc
const A = (Math.asin(sinA) * 180) / Math.PI
let rotate = 0
if (lng_b > lng_a && lat_b > lat_a) rotate = A
else if (lng_b > lng_a && lat_b < lat_a) rotate = 180 - A
else if (lng_b < lng_a && lat_b < lat_a) rotate = 180 - A
else if (lng_b < lng_a && lat_b > lat_a) rotate = 360 + A
else if (lng_b > lng_a && lat_b == lat_a) rotate = 90
else if (lng_b < lng_a && lat_b == lat_a) rotate = 270
else if (lng_b == lng_a && lat_b > lat_a) rotate = 0
else if (lng_b == lng_a && lat_b < lat_a) rotate = 180
if (rotate > 360) {
rotate = rotate - 360
}
return rotate
}
到了這里,關于微信小程序-地圖上的圖標計算旋轉值朝向經緯度計算的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!