Atlaslog
Atlaslog / Field Notes / Tiles
Field note · Tiles

Baidu tile numbering is offset from the XYZ grid

Quick answer

Computing Baidu tile numbers with Google's XYZ formula gives x=215971, y=99264 at z18 for Tiananmen, while the real tile is x=209317, y=96843. Baidu numbering is based on BD09MC with its own origin and per-level shift, so every row of a stitched image is displaced.

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: Baidu tile service / Leaflet 1.9.x
Symptom
Checklist
  1. Record a real tile URL for a known place at z18 from the Baidu map
  2. Compute the same point with the XYZ formula and diff the numbers
  3. Divide the diff by 2^z to tell an origin shift from a scale difference
  4. Check whether BD-09 lng/lat was mixed with BD09MC plane coordinates
  5. Compare a resolution-based computation against the observed numbering
Fix

Do not apply XYZ math to Baidu tiles: use the Baidu JS API `getTileUrl` or a maintained Leaflet Baidu plugin. If you must compute, divide BD09MC metres by the level resolution and then add Baidu's own origin offset.

Code
const z = 18;
const lng = 116.410172, lat = 39.916634;
const n = Math.pow(2, z);
const xXyz = Math.floor((lng + 180) / 360 * n);          // 215971
const yXyz = Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) +
             1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * n);  // 99264
const xBaidu = 209317, yBaidu = 96843;
const RES = [0, 0, 0,
  262144, 131072, 65536, 32768, 16384, 8192, 4096,
  2048, 1024, 512, 256, 128, 64, 32, 16, 8];

function baiduTile(mx, my, z) {
  const res = RES[z];
  const x = Math.floor(mx / res);
  const y = Math.floor(my / res);
  return [x, y];
}
baiduTile(12962180, 4859510, 18);
// 与百度实际编号 209317 / 96843 仍差一个平移量,不能直接用
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). Baidu tile numbering is offset from the XYZ grid. https://www.jingweizhi.com/en/cookbook/baidu-tile-origin.html (accessed 2026-11-03).