首页 > 其他分享 >腾讯经纬度转百度,百度转GCJ02

腾讯经纬度转百度,百度转GCJ02

时间:2022-12-30 18:00:20浏览次数:37  
标签:经纬度 GCJ02 CoordinateUtil let 百度 lat lng pi Math

// 腾讯坐标转百度坐标
export const txMapToBdMap = (lng, lat) => {
  // eslint-disable-next-line camelcase
  const x_pi = (3.14159265358979324 * 3000.0) / 180.0
  const x = lng
  const y = lat
  // eslint-disable-next-line camelcase
  const z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi)
  // eslint-disable-next-line camelcase
  const theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi)
  const lngs = z * Math.cos(theta) + 0.0065
  const lats = z * Math.sin(theta) + 0.006

  return { lng: lngs, lat: lats }
}
export const CoordinateUtil = {
  x_pi: (3.14159265358979324 * 3000.0) / 180.0,
  // pai
  pi: 3.1415926535897932384626,
  // 离心率
  ee: 0.00669342162296594323,
  // 长半轴
  a: 6378245.0,
  //  // 百度转国测局
  //  bd09togcj02: function(bd_lon, bd_lat) {
  //      let x = bd_lon - 0.0065;
  //      let y = bd_lat - 0.006;
  //      let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * CoordinateUtil.x_pi);
  //      let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * CoordinateUtil.x_pi);
  //      let gg_lng = z * Math.cos(theta);
  //      let gg_lat = z * Math.sin(theta);
  //      return {
  //          lng: gg_lng,
  //          lat: gg_lat
  //      }
  //  },
  // 百度转84
  bd09togcj02: function (bd_lon, bd_lat) {
    let x = bd_lon - 0.0065
    let y = bd_lat - 0.006
    let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * CoordinateUtil.x_pi)
    let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * CoordinateUtil.x_pi)
    let gg_lng = z * Math.cos(theta)
    let gg_lat = z * Math.sin(theta)
    return CoordinateUtil.gcj02towgs84(gg_lng, gg_lat)
  },
  // 国测局转百度
  gcj02tobd09: function (lng, lat) {
    let z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * CoordinateUtil.x_pi)
    let theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * CoordinateUtil.x_pi)
    let bd_lng = z * Math.cos(theta) + 0.0065
    let bd_lat = z * Math.sin(theta) + 0.006
    return {
      lng: bd_lng,
      lat: bd_lat
    }
  },
  // 国测局转84
  gcj02towgs84: function (lng, lat) {
    let dlat = CoordinateUtil.transformlat(lng - 105.0, lat - 35.0)
    let dlng = CoordinateUtil.transformlng(lng - 105.0, lat - 35.0)
    let radlat = (lat / 180.0) * CoordinateUtil.pi
    let magic = Math.sin(radlat)
    magic = 1 - CoordinateUtil.ee * magic * magic
    let sqrtmagic = Math.sqrt(magic)
    dlat = (dlat * 180.0) / (((CoordinateUtil.a * (1 - CoordinateUtil.ee)) / (magic * sqrtmagic)) * CoordinateUtil.pi)
    dlng = (dlng * 180.0) / ((CoordinateUtil.a / sqrtmagic) * Math.cos(radlat) * CoordinateUtil.pi)
    let mglat = lat + dlat
    let mglng = lng + dlng
    //  return {
    //      lng: lng * 2 - mglng,
    //      lat: lat * 2 - mglat
    //  };
    return [lng * 2 - mglng, lat * 2 - mglat]
  },
  // 经度转换
  transformlat: function (lng, lat) {
    let ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng))
    ret += ((20.0 * Math.sin(6.0 * lng * CoordinateUtil.pi) + 20.0 * Math.sin(2.0 * lng * CoordinateUtil.pi)) * 2.0) / 3.0
    ret += ((20.0 * Math.sin(lat * CoordinateUtil.pi) + 40.0 * Math.sin((lat / 3.0) * CoordinateUtil.pi)) * 2.0) / 3.0
    ret += ((160.0 * Math.sin((lat / 12.0) * CoordinateUtil.pi) + 320 * Math.sin((lat * CoordinateUtil.pi) / 30.0)) * 2.0) / 3.0
    return ret
  },
  // 纬度转换
  transformlng: function (lng, lat) {
    let ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng))
    ret += ((20.0 * Math.sin(6.0 * lng * CoordinateUtil.pi) + 20.0 * Math.sin(2.0 * lng * CoordinateUtil.pi)) * 2.0) / 3.0
    ret += ((20.0 * Math.sin(lng * CoordinateUtil.pi) + 40.0 * Math.sin((lng / 3.0) * CoordinateUtil.pi)) * 2.0) / 3.0
    ret += ((150.0 * Math.sin((lng / 12.0) * CoordinateUtil.pi) + 300.0 * Math.sin((lng / 30.0) * CoordinateUtil.pi)) * 2.0) / 3.0
    return ret
  },
  getWgs84xy: function (x, y) {
    // 先转 国测局坐标
    let doubles_gcj = CoordinateUtil.bd09togcj02(x, y) // (x 117.   y 36. )
    // 国测局坐标转wgs84
    let doubles_wgs84 = CoordinateUtil.gcj02towgs84(doubles_gcj.lng, doubles_gcj.lat)
    // 返回 纠偏后 坐标

    return doubles_wgs84
  }
}

 

标签:经纬度,GCJ02,CoordinateUtil,let,百度,lat,lng,pi,Math
From: https://www.cnblogs.com/dcyd/p/17015506.html

相关文章

  • WordPress添加百度第三方登录功能
    OpenSocial操作简单适用范围广;可操作性强;无第三方平台、无接口文件冗余;功能特点社交登陆:腾讯QQ、微博、微信、豆瓣、谷歌、微软、Facebook、Twitter、Github等社交分享:QQ......
  • 实战练习:用airtest-selenium脚本爬取百度热搜标题
    1.前言很多同学,使用AirtestIDE都是做移动端的测试,其实它还有个隐藏功能,就是做web自动化测试。搞网页测试,使用AirtestIDE的好处是,能借助selenium的辅助窗,帮助我们快捷地......
  • 姚乃琳博士所有课程 百度网盘下载分享
    姚乃琳博士所有课程 百度网盘下载分享,有需要的可以直接搜v信公众号:稀饭资料库......
  • python爬取百度图库多张图片
    hello啊,各位小伙伴,眨眼间7月份过去了,八月已经悄然来临,不知道八月大家又立了什么样的flag,作为一个低产的公众号运营者,想想都是一阵莫名奇妙的辛酸,每月就三四篇文章,唉…不多......
  • Python 通过关键词下载百度图片
    打开百度图片后,输入相关关键词,根据分析,发现百度图片初始只会渲染部分图像到页面上,随着滚轮下滚,就会请求新的数据,因此我们可以判断页面是经过ajax请求数据后,渲染至页面。百度......
  • 使用xpath爬取对应百度贴吧下面的帖子图片
    hello,小伙伴们,上次给大家分享了如何使用python的正则匹配爬取百思不得姐的网站代码,虽然说正则匹配爬取网站的执行效率高,但是正则匹配的规则编写着实是令人头痛的一件事。今......
  • 如何在Excel表格中使用百度翻译Byserver公式?
     时光荏苒,2022年即将过去,大家今年的工作也到了收尾的阶段。为了让提高大家的工作效率,Excel网络函数库推出了百度翻译byserver公式,使用该公式,能够快速批量的翻译表格里的......
  • 百度指数 Cipher-Text、百度翻译 Acs-Token 逆向分析
    K哥之前写过一篇关于百度翻译逆向的文章,也在bilibili上出过相应的视频,最近在K哥爬虫交流群中有群友提出,百度翻译新增了一个请求头参数Acs-Token,如果不携带该参数,直接......
  • 使用百度地图API申请密钥流程
    1、百度中搜索百度地图进行查找  2、点击控制台  3、进行开发者认证   有这个标识即可进行申请密钥 4、申请密钥        点击应用管理中的......
  • php 两地经纬度获取距离
    composerrequirejeroendesloovere/distance<?phpnamespaceLonLatFilterShop;useJeroenDesloovere\Distance\Distance;usethink\Exception;classLonLatFil......