返回排行榜

hujiulong/gcoord

TypeScript

地理坐标系转换工具

mapwgs84gcj-02bd-09geojsonjavascript
Star 增长趋势
Star
3.3k
Forks
401
周增长
Issues
1
1k2k3k
2018年2月2020年11月2023年9月2026年7月
制品库npmnpm install gcoord
README

Gcoord

English | 简体中文

npm version codecov gzip size LICENSE 996.icu

gcoord (geographic coordinates) is a lightweight JavaScript library for transforming coordinates between common web map coordinate reference systems. It helps normalize coordinates from GPS, Baidu Maps, AMap, Google China Maps, and other map providers.

gcoord supports coordinate arrays and GeoJSON objects, has no runtime dependencies, and works in Node.js, modern browsers, and React Native. The browser global build is about 3 KB after gzip.

For background reading, see Geographic Coordinate Systems.

Before publishing, displaying, distributing, or otherwise using map data, make sure you comply with the laws and regulations that apply to your use case.

Surveying and mapping activities may not use an international coordinate system without approval.

  • Surveying and Mapping Law of the People's Republic of China, Article 40 (1)

Navigation electronic maps must undergo spatial position technical processing before public publication, sale, distribution, display, or use.

  • GB 20263-2006, Basic Requirements for Security Processing of Navigation Electronic Maps, 4.1

Installation

Install from npm:

npm install gcoord

Or load the browser global build with a script tag:

<script src="https://unpkg.com/gcoord@1.0.7/dist/gcoord.global.prod.js"></script>

When using a script tag, always pin an exact package version.

Import

CommonJS:

const gcoord = require('gcoord');

ES module:

import gcoord from 'gcoord';

Browser global:

window.gcoord.transform([116.403988, 39.914266], gcoord.WGS84, gcoord.BD09);

Usage

If you receive a GPS coordinate from a phone and need to display it on Baidu Maps, convert it from WGS-84 to BD-09:

const result = gcoord.transform(
  [116.403988, 39.914266], // coordinate: [longitude, latitude]
  gcoord.WGS84, // source CRS
  gcoord.BD09, // target CRS
);

console.log(result); // [116.41661560068297, 39.92196580126834]

gcoord can also transform GeoJSON objects. See the API section for details.

API

transform(input, from, to)

Transforms coordinates from one CRS to another.

Parameters

  • input GeoJSON | string | Array<number>: a GeoJSON object, a GeoJSON string, or a coordinate array.
  • from CRS: the source coordinate reference system.
  • to CRS: the target coordinate reference system.

Returns

GeoJSON | Array<number>

Examples

// Convert a GCJ-02 coordinate to WGS-84.
const result = gcoord.transform([123, 45], gcoord.GCJ02, gcoord.WGS84);
console.log(result); // [122.99395597, 44.99804071]
// Transform coordinates inside a GeoJSON object.
const geojson = {
  type: 'Point',
  coordinates: [123, 45],
};

gcoord.transform(geojson, gcoord.GCJ02, gcoord.WGS84);
console.log(geojson.coordinates); // [122.99395597, 44.99804071]

The return type matches the input type. When the input is a GeoJSON object, transform mutates the input object in place.

CRS

The following coordinate reference systems are supported:

CRS Coordinate format Description
gcoord.WGS84 [lng, lat] WGS-84, the longitude and latitude coordinates returned by GPS devices.
gcoord.GCJ02 [lng, lat] GCJ-02, used by AMap, Google China Maps, Soso Maps, Aliyun Maps, and MapABC.
gcoord.BD09 [lng, lat] BD-09, used by Baidu Maps.
gcoord.BD09LL [lng, lat] Alias of BD-09.
gcoord.BD09MC [x, y] BD-09 meter coordinates, used by Baidu Maps. Unit: meter.
gcoord.BD09Meter [x, y] Alias of BD09MC.
gcoord.Baidu [lng, lat] Alias of BD-09.
gcoord.BMap [lng, lat] Alias of BD-09.
gcoord.AMap [lng, lat] Alias of GCJ-02.
gcoord.WebMercator [x, y] Web Mercator projection, alias of EPSG3857. Unit: meter.
gcoord.WGS1984 [lng, lat] Alias of WGS-84.
gcoord.EPSG4326 [lng, lat] Alias of WGS-84.
gcoord.EPSG3857 [x, y] Web Mercator projection. Unit: meter.
gcoord.EPSG900913 [x, y] Alias of Web Mercator.

Development

npm ci
npm run lint
npm run typecheck
npm test
npm run build

The package is built with tsup, tests run with vitest, and published files are emitted to dist/.

Need More Coordinate Systems?

gcoord focuses on coordinate systems commonly used by web maps. The supported CRS list covers most web map scenarios while keeping the package small. For more specialized geodesy work, consider using proj4js.

License

MIT

相关仓库
redisson/redisson

Redisson: Valkey & Redis Java Client and Real-Time Data Platform. Sync/Async/RxJava/Reactive API. Over 50 Valkey and Redis based Java objects and services: Set, Multimap, SortedSet, Map, List, Queue, Deque, Semaphore, Lock, AtomicLong, Map Reduce, Bloom filter, Spring, Tomcat, Scheduler, JCache API, Hibernate, RPC, local cache..

JavaMavenApache License 2.0javaredis
redisson.pro
24.4k5.5k
emirpasic/gods

GoDS (Go Data Structures) - Sets, Lists, Stacks, Maps, Trees, Queues, and much more

GoGo ModulesOthergogolang
17.4k1.8k
ZCShou/GoGoGo

一个基于 Android 调试 API + 百度地图实现的虚拟定位工具,并且同时实现了一个可以自由移动的摇杆

JavaMavenGNU General Public License v3.0androidjoystick
itexp.blog.csdn.net
10.9k1.2k
domlysz/BlenderGIS

Blender addons to make the bridge between Blender and geographic data

PythonPyPIGNU General Public License v3.0blenderaddon
9.2k1.5k
rastapasta/mapscii

🗺 MapSCII is a Braille & ASCII world map renderer for your console - enter => telnet mapscii.me <= on Mac (brew install telnet) and Linux, connect with PuTTY on Windows

JavaScriptnpmMIT Licenseascii-artmap
9.2k293
visgl/react-map-gl

React friendly API wrapper around MapboxGL JS

TypeScriptnpmOtherreactmap
visgl.github.io/react-map-gl/
8.5k1.4k
google-map-react/google-map-react

Google map library for react that allows rendering components as markers :tada:

JavaScriptnpmMIT Licensereactmap
google-map-react.github.io/google-map-react/map/main/
6.5k853
dillidon/alerts-and-pickers

Advanced usage of UIAlertController and pickers based on it: Telegram, Contacts, Location, PhotoLibrary, Country, Phone Code, Currency, Date...

SwiftMIT Licenseuialertcontrollerpicker
5.8k702
PaulLeCam/react-leaflet

React components for Leaflet maps

TypeScriptnpmOtherleafletmap
react-leaflet.js.org
5.6k902
sshuair/awesome-gis

😎Awesome GIS is a collection of geospatial related sources, including cartographic tools, geoanalysis tools, developer tools, data, conference & communities, news, massive open online course, some amazing map sites, and more.

MIT Licensegisawesome
5.4k831
sacridini/Awesome-Geospatial

Long list of geospatial tools and resources

Creative Commons Zero v1.0 Universalawesome-listawesome
5.2k759
orcaman/concurrent-map

a thread-safe concurrent map for go

GoGo ModulesMIT Licensegolanggo
4.5k555