tianditu-wechat-coordinate
v0.1.1
Published
Convert Tianditu WGS84/CGCS2000 coordinates to the GCJ-02 coordinates used by WeChat maps.
Maintainers
Readme
tianditu-wechat-coordinate
将天地图常见的 WGS84/CGCS2000 经纬度转换为微信小程序地图使用的 GCJ-02 坐标。
安装
npm install tianditu-wechat-coordinate使用
import { wgs84ToGcj02 } from "tianditu-wechat-coordinate";
const coordinate = wgs84ToGcj02({
latitude: 40.262638,
longitude: 116.226886,
});批量转换接口返回的轨迹点:
const points = apiPoints.map(({ lat, lng }) =>
wgs84ToGcj02({ latitude: Number(lat), longitude: Number(lng) }),
);注意事项
- 输入和输出字段均为
latitude、longitude。 - 中国大陆范围外的坐标会原样返回。
- 已是 GCJ-02 的坐标不要再次转换,否则会产生二次偏移。
- CGCS2000 与 WGS84 在一般地图展示场景中差异很小,本包按 WGS84 到 GCJ-02 的方式处理。
License
MIT
