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

废话不多说,开整

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
  }
相关推荐
甜甜的资料库7 小时前
基于微信小程序的睡眠宝系统源码数据库文档
数据库·微信小程序·小程序
华子w9089258597 小时前
SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现
spring boot·微信小程序·uni-app
恰薯条的屑海鸥8 小时前
关于我对各开发语言的看法与接下来的文章内容
开发语言·学习·微信小程序·网站开发·全栈开发
勿念4368 小时前
基于鸿蒙(HarmonyOS5)的打车小程序
华为·小程序·harmonyos
Stanford_11069 小时前
关于大数据的基础知识(二)——国内大数据产业链分布结构
大数据·开发语言·物联网·微信小程序·微信公众平台·twitter·微信开放平台
邹荣乐12 小时前
uni-app开发微信小程序的报错[渲染层错误]排查及解决
前端·微信小程序·uni-app
weixin_1772972206914 小时前
盲盒一番赏小程序:引领盲盒新潮流
小程序
chaosama1 天前
微信小程序带参分享、链接功能
微信小程序·小程序
胡西风_foxww1 天前
微信小程序动态组件加载的应用场景与实现方式
微信小程序·应用·加载·动态组件
ALLSectorSorft1 天前
上门服务小程序会员系统框架设计
小程序·apache