coordtransform
提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
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.
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.
Where it fits
- Convert raw GPS coordinates to GCJ-02 so pins land in the correct position on Gaode or iOS maps in China
- Display Baidu Maps SDK location data on a non-Baidu map layer without position drift
- Add coordinate conversion to a Node.js mapping service with a single npm install and no external dependencies
- Build a browser-side map app that accepts GPS input and plots it correctly on Chinese map tiles