当前位置:网站首页>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
}
边栏推荐
- ThreadLocal
- js中常用的几种遍历处理数据的方法梳理
- jmeter分布式压测
- Analysis: What makes the Nomad Bridge hack unique
- 电子组装行业对MES管理系统的需求分析
- typescript52 - simplify generic function calls
- 哎,又跟HR在小群吵了一架!
- Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
- Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
- 在Activity中获取另一个XML文件的控件
猜你喜欢
LeetCode third topic (the Longest Substring Without Repeating Characters) trilogy # 3: two optimization
持续投入商品研发,叮咚买菜赢在了供应链投入上
The 600MHz band is here, will it be the new golden band?
typescript53-泛型约束
114. How to find the cause of Fiori Launchpad routing error by single-step debugging
splice随机添加和删除的写法
lombok注解@RequiredArgsConstructor的使用
持续投入商品研发,叮咚买菜赢在了供应链投入上
电子制造企业部署WMS仓储管理系统的好处是什么
typescript58 - generic classes
随机推荐
Tanabata festival coming, VR panoramic look god assists for you
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
ASP.NET 获取数据库的数据并写入到excel表格中
Quickly build a website with static files
互斥锁、读写锁、自旋锁,以及原子操作指令xaddl、cmpxchg的使用场景剖析
特征值与特征向量
循环绕过问题
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
Sticker Spelling - Memory Search / Shape Pressure DP
持续投入商品研发,叮咚买菜赢在了供应链投入上
LDO investigation
2022年上半年各大厂Android面试题整理及答案解析(持续更新中......)
Analysis: What makes the Nomad Bridge hack unique
计算首屏时间
typescript56 - generic interface
ThreadLocal
nodejs+npm的安装与配置
持续投入商品研发,叮咚买菜赢在了供应链投入上
GNSS【0】- 专题