微信小程序-地图上的图标计算旋转值朝向经纬度计算

废话不多说,开整

js 复制代码
// 参数为寄件人经纬度和收件人经纬度 
// 根据寄收件人经纬度弧度π进行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
  }
相关推荐
黄华SJ520it1 天前
预约上门系统开发:懒人经济下的商业机遇与技术实践
小程序·系统开发
软件技术新观察1 天前
2026年北京教育医疗小程序与APP定制开发:十大服务商实力测评
大数据·小程序
万岳科技程序员小金1 天前
真人数字人小程序如何开发?AI数字人平台搭建流程全面解析
人工智能·小程序·ai数字人系统源码·ai数字人平台搭建·ai数字人小程序开发
didiplus2 天前
我在GitHub刷到一个诗词API,顺手写了款小程序
微信小程序
言乐62 天前
Python实现可运行解密游戏游戏框架
python·游戏·小程序·游戏程序·关卡设计
2501_915106322 天前
iOS 软件测试工具性能监控、日志分析 KeyMob、Instruments等
android·ios·小程序·https·uni-app·iphone·webview
云迈科技-软件定制开发2 天前
2026 AI智能体小程序APP开发怎么做:从场景规划到上线交付的完整参考
大数据·人工智能·小程序
小码哥0682 天前
医院陪诊小程序怎么开发-医院陪诊小程序源码功能-微信小程序 医院健康陪诊陪护系统
微信小程序·小程序·医院陪诊·陪诊系统·陪诊陪诊
书中枫叶3 天前
从「上次几点喂奶」到全栈小程序:我做了个喂宝助手
mongodb·微信小程序·node.js
黄华SJ520it3 天前
柯尔嫚商城模式开发:从概念到实现的完整指南
小程序·系统开发