explaingit

wandergis/coordtransform

4,627JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A zero-dependency JavaScript utility that converts GPS coordinates between the three mapping systems used in China, fixing the position offset that makes raw GPS pins appear hundreds of meters from their real location on Chinese maps.

Mindmap

mindmap
  root((coordtransform))
    What it does
      GPS coordinate conversion
      China map systems
      Zero dependencies
    Coordinate systems
      WGS84 GPS standard
      GCJ-02 China national
      BD-09 Baidu only
    Use cases
      Map pin accuracy
      Baidu to Gaode
      GPS track display
    Setup
      npm install
      Browser script tag
      AMD module support
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Convert raw GPS coordinates to GCJ-02 so pins land in the correct position on Gaode or iOS maps in China

USE CASE 2

Display Baidu Maps SDK location data on a non-Baidu map layer without position drift

USE CASE 3

Add coordinate conversion to a Node.js mapping service with a single npm install and no external dependencies

USE CASE 4

Build a browser-side map app that accepts GPS input and plots it correctly on Chinese map tiles

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min

No external dependencies, install via npm or include a script tag directly in a browser page.

In plain English

coordtransform is a JavaScript utility for converting location coordinates between three different mapping systems used in China. The problem it solves is a practical one: China legally requires all domestically published maps to encrypt GPS coordinates using a government standard, so raw GPS latitude and longitude values do not line up with Chinese map tiles. If you place a GPS pin on a Chinese map without converting it first, the pin can appear hundreds of meters away from the real location. The three coordinate systems involved are WGS84, GCJ-02, and BD-09. WGS84 is the international standard used by GPS hardware and most maps outside China. GCJ-02, sometimes called Mars Coordinates, is China's national standard and is used by Gaode maps, iOS maps inside China, and Google's China-domain maps. BD-09 is Baidu's own system, which adds a second layer of offset on top of GCJ-02, and is used exclusively by Baidu Maps and Baidu's mobile SDK. The library exposes simple conversion functions: Baidu to national standard, national standard to Baidu, GPS to national standard, and national standard to GPS. Each function takes a longitude and latitude pair and returns the converted pair. The README includes working code examples for all four directions and shows the small but real numeric differences the conversion produces. The library works in Node.js with a standard npm install, and also in browsers either by including the script tag directly or by loading it with an AMD module loader. A Python version and a command-line version are mentioned as separate companion repositories. The project was created because the author needed to display Baidu SDK coordinates on a non-Baidu map tile layer, and the position offset made the data unusable without conversion. The code is concise and has no external dependencies.

Copy-paste prompts

Prompt 1
I am building a web map that shows GPS tracks on Gaode Maps in China. Show me how to use coordtransform in Node.js to convert all my WGS84 coordinates to GCJ-02 before plotting them.
Prompt 2
How do I convert Baidu Maps SDK location data in BD-09 format to standard WGS84 GPS coordinates using coordtransform?
Prompt 3
Write a Node.js function that takes an array of objects with lat and lng fields in WGS84 and returns them converted to GCJ-02 for display on an iOS map in China.
Prompt 4
Show me how to include coordtransform in a browser page using a script tag and convert a single GPS coordinate pair to BD-09 for use with Baidu Maps.
Open on GitHub → Explain another repo

← wandergis on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.