npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@giszhc/coords-transform

v1.0.3

Published

一个提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具模块

Downloads

246

Readme

coords transform 坐标转换

一个简单的 JavaScript/TypeScript 库,用于在不同坐标系之间进行转换:BD-09(百度坐标系)、GCJ-02(火星坐标系)和 WGS-84 坐标系。该库提供了以下坐标系之间的转换函数:

  • BD-09 (百度坐标系)GCJ-02 (火星坐标系)(用于谷歌、高德等地图)
  • WGS-84GCJ-02(用于 GPS)

参考coordtransform重写的TS版本

https://github.com/wandergis/coordtransform

安装

你可以通过 npm 安装该库:

pnpm install @giszhc/coords-transform

使用方法

安装完成后,你可以在项目中导入并使用转换函数。以下是可用的函数:

bd09ToGcj02(bdLng: number, bdLat: number) => [number, number]

将百度 BD-09 坐标系的经纬度转换为 GCJ-02 坐标系(谷歌、高德等使用的坐标系)。

参数:

  • bdLng (number): 百度坐标系中的经度。
  • bdLat (number): 百度坐标系中的纬度。

返回值:

  • 返回一个包含两个数值的数组,分别是转换后的 GCJ-02 坐标系中的经度和纬度。

示例:

import { bd09ToGcj02 } from "@giszhc/coords-transform";

const [lng, lat] = bd09ToGcj02(116.404, 39.915);
console.log(lng, lat);

gcj02ToBd09(lng: number, lat: number) => [number, number]

将 GCJ-02 坐标系的经纬度转换为百度 BD-09 坐标系。

参数:

  • lng (number): GCJ-02 坐标系中的经度。
  • lat (number): GCJ-02 坐标系中的纬度。

返回值:

  • 返回一个包含两个数值的数组,分别是转换后的 BD-09 坐标系中的经度和纬度。

示例:

import { gcj02ToBd09 } from "@giszhc/coords-transform";

const [bdLng, bdLat] = gcj02ToBd09(116.404, 39.915);
console.log(bdLng, bdLat);

wgs84ToGcj02(lng: number, lat: number) => [number, number]

将 WGS-84 坐标系的经纬度转换为 GCJ-02 坐标系。

参数:

  • lng (number): WGS-84 坐标系中的经度。
  • lat (number): WGS-84 坐标系中的纬度。

返回值:

  • 返回一个包含两个数值的数组,分别是转换后的 GCJ-02 坐标系中的经度和纬度。

示例:

import { wgs84ToGcj02 } from "@giszhc/coords-transform";

const [gcjLng, gcjLat] = wgs84ToGcj02(116.404, 39.915);
console.log(gcjLng, gcjLat);

gcj02ToWgs84(lng: number, lat: number) => [number, number]

将 GCJ-02 坐标系的经纬度转换为 WGS-84 坐标系。

参数:

  • lng (number): GCJ-02 坐标系中的经度。
  • lat (number): GCJ-02 坐标系中的纬度。

返回值:

  • 返回一个包含两个数值的数组,分别是转换后的 WGS-84 坐标系中的经度和纬度。

示例:

import { gcj02ToWgs84 } from "@giszhc/coords-transform";

const [wgsLng, wgsLat] = gcj02ToWgs84(116.404, 39.915);
console.log(wgsLng, wgsLat);