当前位置:网站首页>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
}
边栏推荐
- Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
- KunlunBase 1.0 is released!
- 【正则表达式】笔记
- Summary of GNSS Articles
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- 企业虚拟偶像产生了实质性的价值效益
- JS 保姆级贴心,从零教你手写实现一个防抖debounce方法
- Quickly build a website with static files
- Analysis: What makes the Nomad Bridge hack unique
- 简单的线性表的顺序表示实现,以及线性表的链式表示和实现、带头节点的单向链表,C语言简单实现一些基本功能
猜你喜欢
随机推荐
typescript50-交叉类型和接口之间的类型说明
typescript57-数组泛型接口
工程制图平面投影练习
哎,又跟HR在小群吵了一架!
ThreadLocal
MongoDB数据接入实践
Observability:你所需要知道的关于 Syslog 的一些知识
GNSS[0]- Topic
观察者模式
持续投入商品研发,叮咚买菜赢在了供应链投入上
typescript53-泛型约束
工程制图复习题(带答案)
Web3 security risks daunting?How should we respond?
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之三:两次优化
splice随机添加和删除的写法
nodejs install multi-version version switching
typescript50 - type specification between cross types and interfaces
【无标题】
lombok注解@RequiredArgsConstructor的使用
多渠道打包








