Article · 2023-04-28

Coordinate System Conversion in Tencent, Amap, and Baidu Maps: Technical Details and Engineering Practice

For developers, the practical problem is clear: GPS receivers provide WGS-84 coordinates, but displaying them directly on Chinese map services produces positioning errors. A real location's WGS-84 coordinates shown on a GCJ-02 map (such as Amap or Tencent Maps) can be off by 100–700 meters. Anyone building location features in mainland China must implement correct coordinate system conversion—between WGS-84 and GCJ-02, between GCJ-02 and BD-09—to ensure accurate positioning.

Coordinate Systems Used by Different Map Services

In practice, China's major map providers use different coordinate systems:

Coordinate Conversion Implementation

Understanding the coordinate system differences, we can now discuss practical conversion methods. Common needs include converting WGS-84 (from GPS) to GCJ-02 (Mars coordinates), and converting GCJ-02 to BD-09 (Baidu coordinates).

Converting between WGS-84 and GCJ-02 uses an offset algorithm. Because the GCJ-02 encryption algorithm is restricted by Chinese regulations, official interfaces for converting GCJ-02 back to WGS-84 are not published. Fortunately, open-source implementations in various languages are available. The basic principle: to convert WGS-84 to GCJ-02, if the coordinate is within mainland China, the algorithm calculates offsets Δlng and Δlat (in longitude and latitude directions) and adds them to the original coordinates, yielding the encrypted GCJ-02 coordinate. To approximately reverse GCJ-02 back to WGS-84, you subtract the calculated offset. Because the offset algorithm is nonlinear, recovering exact coordinates requires iterative approximation to achieve high precision, but in typical applications, a single reverse calculation provides sufficient accuracy.

Converting between GCJ-02 and BD-09 deserves closer attention. Baidu publishes a coordinate conversion API that converts GCJ-02 (or WGS-84) to BD-09, but you can also implement the transformation using publicly available formulas. The core algorithm is straightforward, based on fixed small offsets and trigonometric transformations. Here is a Python implementation:

import math

# GCJ-02 to BD-09
def gcj02_to_bd09(lng, lat):
    x = lng
    y = lat
    z = math.sqrt(x * x + y * y) + 0.00002 * math.sin(y * math.pi)
    theta = math.atan2(y, x) + 0.000003 * math.cos(x * math.pi)
    bd_lng = z * math.cos(theta) + 0.0065
    bd_lat = z * math.sin(theta) + 0.006
    return bd_lng, bd_lat

# BD-09 to GCJ-02
def bd09_to_gcj02(bd_lng, bd_lat):
    x = bd_lng - 0.0065
    y = bd_lat - 0.006
    z = math.sqrt(x * x + y * y) - 0.00002 * math.sin(y * math.pi)
    theta = math.atan2(y, x) - 0.000003 * math.cos(x * math.pi)
    gcj_lng = z * math.cos(theta)
    gcj_lat = z * math.sin(theta)
    return gcj_lng, gcj_lat

In these formulas, the constants 0.0065 and 0.006 are the fixed offsets Baidu applies to longitude and latitude, each adding roughly six ten-thousandths of a degree; combined with the small sine terms 0.00002 and 0.000003, the transformation is smooth and introduces only minor perturbations. These constants encode the offset of BD-09 relative to GCJ-02. Using these functions, you can reliably convert GCJ-02 coordinates to BD-09, or restore Baidu coordinates back to Mars coordinates, with precision sufficient for typical mapping applications.

Common Pitfalls and Engineering Practices

In production systems, several hazards and practices bear attention:

© 2026 Yuxu Ge ·