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.
Symptom
- The XYZ formula returns `x = 215971, y = 99264` while the network panel shows `x = 209317, y = 96843`
- Each stitched row is offset, and the error grows toward the east
- Tiles exist only from level 3 upward; levels 1 and 2 are schematic only
Checklist
- Record a real tile URL for a known place at z18 from the Baidu map
- Compute the same point with the XYZ formula and diff the numbers
- Divide the diff by 2^z to tell an origin shift from a scale difference
- Check whether BD-09 lng/lat was mixed with BD09MC plane coordinates
- 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
- Dividing BD09MC coordinates by the resolution and assuming the quotient is final, while the platform origin offset remains
- Converting BD-09 lng/lat with the XYZ formula, which mixes geographic and projected units
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
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).