当前位置:网站首页>天地图坐标系转高德坐标系 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
}
边栏推荐
猜你喜欢
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?

114. 如何通过单步调试的方式找到引起 Fiori Launchpad 路由错误的原因

600MHz频段来了,它会是新的黄金频段吗?

typescript54 - generic constraints
![[store mall project 01] environment preparation and testing](/img/78/415b18a26fdc9e6f59b59ba0a00c4f.png)
[store mall project 01] environment preparation and testing

nodejs安装及环境配置

DDTL:远距离的域迁移学习

Android interview questions and answer analysis of major factories in the first half of 2022 (continuously updated...)

Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system

特征值与特征向量
随机推荐
nodejs installation and environment configuration
字符串的排列
电子组装行业对MES管理系统的需求分析
即席查询——Presto
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之三:两次优化
dynamic memory two
jmeter distributed stress test
Deng Qinglin, Alibaba Cloud Technical Expert: Best Practices for Disaster Recovery across Availability Zones and Multiple Lives in Different Locations on the Cloud
分析:Nomad Bridge黑客攻击的独特之处
typescript52-简化泛型函数调用
KunlunBase 1.0 is released!
有没有jdbc 链接优炫数据库文档及示例?
Is there any jdbc link to Youxuan database documentation and examples?
快速入门EasyX图形编程
Array_Sliding window | leecode brushing notes
MySQL回表指的是什么
Thinkphp commonly used techniques
一个项目的整体测试流程有哪几个阶段?测试方法有哪些?
- heavy OpenCV 】 【 mapping
FeatureNotFound( bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: