当前位置:网站首页>Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
Sky map coordinate system to Gaode coordinate system WGS84 to GCJ02
2022-08-04 01:32:00 【sr_www】
let [lng, lat] = [116.391358342, 39.9049662090001]
console.log([lng, lat].toString())
console.log(wgs84Togcj02(lng, lat).toString())
function wgs84Togcj02(lng, lat) {
if (out_of_china(lng, lat)) {
console.log('国外')
return [lng, lat]
}
//定义一些常量
//GCJ02 转换为 WGS84
const x_PI = 3.14159265358979324 * 3000.0 / 180.0
const PI = 3.1415926535897932384626
const a = 6378245.0
const ee = 0.00669342162296594323
let dlat = transformlat(lng - 105.0, lat - 35.0)
let dlng = transformlng(lng - 105.0, lat - 35.0)
let radlat = lat / 180.0 * PI
let magic = Math.sin(radlat)
magic = 1 - ee * magic * magic
let sqrtmagic = Math.sqrt(magic)
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI)
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI)
var mglat = lat + dlat
var mglng = lng + dlng
return [mglng, mglat]
//return [lng * 2 - mglng, lat * 2 - mglat]
}
function out_of_china(lng, lat) {
return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false)
}
function transformlat(lng, lat) {
const x_PI = 3.14159265358979324 * 3000.0 / 180.0
const PI = 3.1415926535897932384626
const a = 6378245.0
const ee = 0.00669342162296594323
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 * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0
return ret
}
function transformlng(lng, lat) {
const x_PI = 3.14159265358979324 * 3000.0 / 180.0
const PI = 3.1415926535897932384626
const a = 6378245.0
const ee = 0.00669342162296594323
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 * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0
return ret
}
边栏推荐
- lombok注解@RequiredArgsConstructor的使用
- 谁说程序员不懂浪漫,表白代码来啦~
- Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar
- typescript54-泛型约束
- boot issue
- typescript55 - generic constraints
- MySQL回表指的是什么
- 持续投入商品研发,叮咚买菜赢在了供应链投入上
- Promise 解决阻塞式同步,将异步变为同步
- typescript57-数组泛型接口
猜你喜欢
随机推荐
网页三维虚拟展厅为接入元宇宙平台做基础
nodejs installation and environment configuration
谁说程序员不懂浪漫,表白代码来啦~
How to find the cause of Fiori Launchpad routing errors by single-step debugging
boot issue
js中常用的几种遍历处理数据的方法梳理
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
splice随机添加和删除的写法
字符串变形
typescript48-函数之间的类型兼容性
C 学生管理系统_添加学生
七夕佳节即将来到,VR全景云游为你神助攻
this巩固训练,从两道执行题加深理解闭包与箭头函数中的this
MongoDB数据接入实践
Slipper —— 虚点,最短路
优秀的测试/开发程序员,是怎样修炼的?步步为营地去执行......
KunlunBase 1.0 is released!
ASP.NET 获取数据库的数据并写入到excel表格中
电子制造企业部署WMS仓储管理系统的好处是什么
Apache DolphinScheduler actual combat task scheduling platform - a new generation of distributed workflow









