Atlaslog
Atlaslog / Field Notes / Coordinates & projections
Field note · Coordinates & projections

Same points converted twice: offset grows from 555 m to 1110 m

Quick answer

The backend already stores GCJ-02 but records no CRS tag, so the frontend converts again. GCJ-02 encryption is not idempotent: f(f(x)) keeps adding the same north-east increment instead of undoing it.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: gcoord 1.0.x · turf.js 7.x · Leaflet 1.9.x
Symptom
Checklist
  1. Take one known point, subtract the interface value from the on-map value to get the actual offset vector.
  2. Compute the single-pass WGS84 to GCJ-02 result and compare it with the API return; a match means the backend already converted.
  3. Copy the API response into gcoord.transform and run it once in the console to see whether it moves another ~555 m.
  4. Search the frontend for a global coordinate middleware or an axios response interceptor doing the conversion.
  5. Check whether the stored rows carry any CRS marker at all; if not, the pipeline is guessing.
Fix

Convert exactly once, preferably at the data-production end, and write the CRS into the payload so downstream code never has to infer it.

Code
const a = turf.point([116.397428, 39.909230]);   // WGS84 原始点
const b = turf.point([116.403672, 39.910634]);   // 应得 GCJ-02
const c = turf.point([116.409922, 39.912036]);   // 实际渲染点

turf.distance(a, b, { units: 'meters' });  // 555.6
turf.distance(a, c, { units: 'meters' });  // 1110.2
turf.distance(b, c, { units: 'meters' });  // 554.6
{
  "type": "FeatureCollection",
  "coordSys": "GCJ02",
  "features": [
    { "type": "Feature",
      "properties": { "name": "国贸" },
      "geometry": { "type": "Point", "coordinates": [116.403672, 39.910634] } }
  ]
}
const SRC = 'WGS84', DST = 'GCJ02';
function normalize(fc, target) {
  const from = fc.coordSys || 'WGS84';
  if (from === target) return fc;                    // 已经一致,直接返回
  return gcoord.transform(fc, gcoord[from], gcoord[target]);
}
const data = normalize(resp.data, 'GCJ02');
Watch out
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

Atlaslog (2026). Same points converted twice: offset grows from 555 m to 1110 m. https://www.jingweizhi.com/en/cookbook/gcj02-double-convert.html (accessed 2026-11-03).