当前位置:网站首页>天地图坐标系转高德坐标系 WGS84转GCJ02
天地图坐标系转高德坐标系 WGS84转GCJ02
2022-08-04 01:31: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
}
边栏推荐
- MongoDB数据接入实践
- nodejs install multi-version version switching
- 无代码7月热讯 | 微软首推数字联络中心平台;全球黑客马拉松...
- typescript51 - basic use of generics
- C # WPF equipment monitoring software (classic) - the next
- pygame 中的transform模块
- .NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
- typescript48-函数之间的类型兼容性
- KunlunBase 1.0 发布了!
- Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
猜你喜欢

Web3 security risks daunting?How should we respond?

Getting started with MATLAB 3D drawing command plot3

JS 从零教你手写节流throttle

jmeter跨平台运行csv等文件

typescript53 - generic constraints

initramfs详解----添加硬盘驱动并访问磁盘

Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar

GraphQL背后处理及执行过程是什么

【日志框架】

Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
随机推荐
js中常用的几种遍历处理数据的方法梳理
typescript56 - generic interface
jmeter分布式压测
静态/动态代理模式
【store商城项目01】环境准备以及测试
dynamic memory two
typescript58 - generic classes
How to find the cause of Fiori Launchpad routing errors by single-step debugging
114. How to find the cause of Fiori Launchpad routing error by single-step debugging
字符串的排列
谁说程序员不懂浪漫,表白代码来啦~
持续投入商品研发,叮咚买菜赢在了供应链投入上
The 600MHz band is here, will it be the new golden band?
html select标签赋值数据库查询结果
观察者模式
【无标题】
【Untitled】
Analysis: What makes the Nomad Bridge hack unique
FeatureNotFound( bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
七夕佳节即将来到,VR全景云游为你神助攻