HKGCode round-trip tester
Convert a latitude and longitude into a grid code, then decode it back to the cell centre.
Coordinates → code
WGS84 decimal degrees
Code → coordinates
Edit the code to test another cell
Test exact HK80 coordinates (no datum shift)
For boundary checks, enter easting then northing in metres. This bypasses approximate geographic conversion.
Decoded result
HKGCode
Centre latitude · ≈ WGS84
Centre longitude · ≈ WGS84
A code identifies an area, not the original point.
Decoded cell bounds & four corners — not whole-coverage limits
These intervals and corners describe only the decoded 2 km, 100 m or 5 m cell, according to its level. [minimum, maximum) includes the minimum but excludes the maximum. For the entire grid’s limits, open “Whole HKGCode coverage” below the map.
- Decoded cell · west–east interval (HK80 E, m)
- Decoded cell · south–north interval (HK80 N, m)
- Decoded cell south-west corner · HK80 E, N / ≈ WGS84 lat, lon
- Decoded cell north-west corner · HK80 E, N / ≈ WGS84 lat, lon
- Decoded cell south-east corner · HK80 E, N / ≈ WGS84 lat, lon
- Decoded cell north-east corner · HK80 E, N / ≈ WGS84 lat, lon
Explore the HKGCode grid
Hover for a live code; click or tap to send a location to the tester.
Connecting to LandsD…
Grid: 2 km at zoom 8–16, 100 m at 17–19, 5 m at 20. Zoom with the map controls; drag to move. Cell lines use the supplied approximate conversion and are not an official grid overlay. Map tiles and optional labels load directly from LandsD. Map API · Terms and copyright
Whole HKGCode coverage · outer limits & four boundary corners
800000 ≤ E < 864000; 800000 ≤ N < 848000. The grid has 32 eastward × 24 northward regions, each 2 km. The north and east outer edges are excluded from encoding. Geometric corners are still valid decoded boundary coordinates.
| Boundary corner | HK80 E (m) | HK80 N (m) | Adjacent region inside |
|---|---|---|---|
| SW · included | 800000 | 800000 | 00 |
| NW · excluded point | 800000 | 848000 | 0Q |
| NE · excluded point | 864000 | 848000 | ZQ |
| SE · excluded point | 864000 | 800000 | Z0 |
The inside corner 5 m cells are SW 000000, NW 0Q0K0K, NE ZQKKKK, SE Z0K0K0. A cell contains its west/south edge, not its east/north edge. ZQ starts at E 862000, N 846000; it is not a code for E 864000, N 848000.
Do not substitute the older transformation API's HK80 input limits. They describe a different service, not HKGCode coverage. Map corner positions use the approximate datum shift, whereas the HK80 figures above are exact grid definitions.
References: LandsD HKGCode definition · Official pseudocode · API manual and worked examples.
Documentation caution: the pseudocode's closing comment says “ZZKKKK”, but that contradicts its own N < 848000 guard and the 24-row published definition. This tester correctly rejects rows R–Z; the northeast limit cell is ZQKKKK.
Code audit & verification results
- Definition and axis order: 32 × 24 regions; pairs are E then N; cell sizes 2000 / 100 / 5 m; exact half-open HK80 domain shared by encoder and map.
- Encoder and decoder: 655,234 numeric assertions passed, including all 768 regions, all 307,200 site cells and 10,000 sampled standard points. Invalid levels, non-finite values, invalid characters, outside rows, and north/east edges are rejected. Lowercase, spaces and hyphens are formatting conveniences, not canonical code characters.
- Four corners: SW, NW, NE, SE are each calculated from their own E/N pair. Live LandsD API matched 5 encoding examples and all four corners of 7 decoded cells, including the 4 extreme 5 m cells. Separate exact north/east edge requests returned HTTP 400.
- Projection and datum: HK80 projection parameters and datum-shift signs checked against LandsD notes. Transverse Mercator series agreed with independent PROJ calculations at 105 points (under 0.001 m); this tests projection math, not the approximate datum shift. The geographic datum limitation above remains.
- Interface and map: direct HK80 input avoids datum ambiguity at boundaries; manual decoding clears the previous input-distance reference; sampled HK80 boundary edges are shown on the map. The basemap and approximate overlay are distinct sources.
Sources and reproducibility: the LandsD definition, pseudocode and API manual are linked above. Automated code checks are not an official certification, and do not validate every possible 5 m cell or guarantee availability of map tiles.