
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
coordinates_convert
Advanced tools
地理坐标转换库,任意类型经纬度数据集(GeoJSON、数组、字符串)实现WGS84、GCJ02、BD09互转。 a utility library for helping convert coordinates from collection like GeoJSON or Array & ect.Use Regular Expression Matching,convert by coordinate-convert
一个转换坐标的处理工具(百度、火星、wg84任意互转),支持任意类型数据(坐标数据必须是经纬度数组)。
支持任意格式的经纬度坐标对数据,经纬度坐标转换
A utility library for helping convert coordinates from string like GeoJSON Array.Use regular expression patter coordinates
经纬度转换,单个坐标转换,不是啥事。百度、高德、maptalks、mapbox都自带相关函数。但是,对于GeoJSON,或者任意格式的经纬度转换。就比较麻烦
你不知道用户给的是几位数组,GeoJSON给的是面坐标数据但是确实二维数组。也不一定是GeoJSON格。如果去判断数据类型,一层层判读下来,……
平时我们去url的search params ,用的就是正则,同理,经纬度坐标转换,用相同方法岂不是更省事。
function getUrlParams (url) {
url || (url = window ? window.location.search : '')
if (!url) {
return {}
}
let params = {}
url.replace(/([^=?&]+)=([^=?&]*)/g, (str, $1, $2) => {
params[$1] = $2
})
return params
}
正则万岁!
经纬度数据转换方法,源自于coordtransform
//百度经纬度坐标转国测局坐标
var bd09togcj02=coordtransform.bd09togcj02(116.404, 39.915);
//国测局坐标转百度经纬度坐标
var gcj02tobd09=coordtransform.gcj02tobd09(116.404, 39.915);
//wgs84转国测局坐标
var wgs84togcj02=coordtransform.wgs84togcj02(116.404, 39.915);
//国测局坐标转wgs84坐标
var gcj02towgs84=coordtransform.gcj02towgs84(116.404, 39.915);
注意:百度坐标转wg84没有提供直接方法,需要先百度经纬度坐标转国测局坐标吗,再国测局坐标转wgs84坐标
但是,遇到GeoJSON字符串转换,或者数组转换,去循环替换,方法可靠,但是代码量太多。
个人觉得用正则表达式转换,代码上,最简洁。所以,就有了此包
测试实例:
let {convertCoords} = require('./index')
let coordinates0 = '[-0.131049, 51.498568]'
let coordinates1 = '-0.131049, 51.498568'
let coordinates2 = '[-0.131049, 51.498568],[-0.131049, 51.498568]'
let coordinates3 = [-0.131049, 51.498568]
let coordinates4 = [[-0.131049, 51.498568], [-0.131049, 51.498568]]
let coordinates5 = {
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [-0.113049, 51.498568]},
"properties": {"name": "point marker"}
}
let coordinates6 = '{"type":"Feature","geometry":{"type":"Point","coordinates":[-0.113049,51.498568]},"properties":{"name":"point marker"}}'
debugger
let m0 = convertCoords(coordinates0, 'bd09', 'wgs84')
let m1 = convertCoords(coordinates1, 'gcj02', 'wgs84')
let m2 = convertCoords(coordinates2, 'gcj02', 'wgs84')
let m3 = convertCoords(coordinates3, 'gcj02', 'wgs84')
let m4 = convertCoords(coordinates4, 'gcj02', 'wgs84')
let m5 = convertCoords(coordinates5, 'gcj02', 'wgs84')
let m6 = convertCoords(coordinates6, 'gcj02', 'wgs84')
console.log(m0)
console.log(m1)
console.log(m2)
console.log(m3)
console.log(m4)
console.log(m5)
console.log(m6)
| 赤道周长(米) | 度数(度) |
|---|---|
| 40076000 | 360 |
| 111322.2222 | 1 |
| 11132.22222 | 0.1 |
| 1113.222222 | 0.01 |
| 111.3222222 | .0001 |
| 11.13222222 | .00001 |
| 1.113222222 | .000001 |
| 0.111322222 | .0000001 |
| 0.011132222 | .00000001 |
对于在线地图,经纬度的读数,精确到小数点之后第六位,已经足够当前gps精度下的使用。
那就先转换为GeoJSON咯,传送门:https://www.npmjs.com/package/geojson
var data = [
{ name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
{ name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 },
{ name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 }
];
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']});
转换结果
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
"properties": {
"name": "Location A"
}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
"properties": {
"name": "Location C"
}
}
]
}
FAQs
地理坐标转换库,任意类型经纬度数据集(GeoJSON、数组、字符串)实现WGS84、GCJ02、BD09互转。 a utility library for helping convert coordinates from collection like GeoJSON or Array & ect.Use Regular Expression Matching,convert by coordinate-convert
The npm package coordinates_convert receives a total of 0 weekly downloads. As such, coordinates_convert popularity was classified as not popular.
We found that coordinates_convert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.