# HEREtile Tiling Scheme

The HEREtile map tiling scheme is based on quad trees, where each higher level of detail splits parent tiles into four equal child tiles. The child tiles are numbered 0 through 3 in a fixed reverse "Z" pattern:

In the figure above:

• Tile 0 is the southwest sub-tile
• Tile 1 is the southeast sub-tile
• Tile 2 is the northwest sub-tile
• Tile 3 is the northeastern sub-tile

This example of tiling is based on raw, non-projected WGS84 latitude/longitude coordinate values, so each child tile covers exactly half its parent's latitude/longitude range per side.

## Special Root Tile

To avoid special handling of level 1 tiles, the level 0 root tile representing the entire world is a little odd.

The familiar -180° to +180° longitude and -90° to +90° latitude range of the world is augmented with a virtual counterpart north of the North Pole. This results in a base coordinate range of -180° to +180° longitude and -90° to +270° latitude, making the level 0 world tile a square with sides of 360°.

From here the root world tile is split in the standard way into four tiles at level 1, resulting in tiles 0 and 1 covering the known world and tiles 2 and 3 generally unused.

This scheme leads to the simple formula that at a given tile level, the latitude and longitude range for a tile can be calculated as:

360° / 2tile level = degrees of latitude and longitude per tile.

So for level 14 tiles that would be:

360° / 214 = 360° / 16384 = 0.02197265625° per tile.

If a location is on the border between two tiles, which tile is it in? For the HEREtile scheme, locations lying on the south-west border of a tile belong to that tile.

More special cases:

• Longitude values of +180° are converted to -180°, so tile references "wrap" over the anti-meridian.
• Latitude values of +90° are owned by their southern tiles.

## HEREtile Identifiers

HEREtile tile identifiers use a packed binary representation, generally stored as values. These values are computed from their logical tile quadkey strings.

Tile quadkeys are strings of tile numbers (0-3) which capture the hierarchy of parent-child tiles from level 1 to the target tile level.

So for the level 5 tile containing San Francisco below, the logical quadkey would be "02123":

It follows that the "level" of a tile quadkey can be directly inferred from the number of digits in the value. So a level 14 tile quad-key will have 14 digits, using only 0, 1, 2 and 3.

The tile quadkey for any latitude/longitude position at a given tile level can be calculated algorithmically using a version of Morton coding. Take this example for the Berlin Hauptbahnhof (central train station) at coordinates 52.52507/13.36937.

Let's calculate the level 14 HEREtile ID: First, we need to calculate the desired tile's (X,Y) coordinates on the world map. Tile (X,Y) coordinates are not latitude/longitude values; they are the tile's integral positional coordinates, indexed from (0,0) in the southwest corner of the world map.

• We find the horizontal (X) tile, index from the longitude value, by dividing the world map longitude range (-180° to +180°) into tile-sized ranges based on the desired zoom level. Per the Special Root Tile above, each level 14 tile cover 0.02197265625 degrees per tile: 180° + 13.36937° = 193.36937° absolute longitude offset from southwest corner. 193.36937° / 0.02197265625° = 8,800.45 = tile X: 8,800 (round down for 0-based indexing)

• Similarly, we find the vertical (Y) tile index, making sure to use the special -90° to +270° latitude range: 90° + 52.52507° = 142.52507° absolute latitude from the south-west corner. 142.52507° / 0.02197265625° = 6,486.47 = tile Y: 6,486 (round down for 0-based indexing)

Next, we need to convert the tile X, Y indexes (8800, 6486) and tile level (14) into a Morton code quadkey:

• Take the simple binary representation of the tile coordinate indexes, zero-padded to the "tile level" number of bits: tile X coordinate: 8800 = 100010011000002 - already 14 bits tile Y coordinate: 6486 = 011001010101102 - zero-padded to 14 bits

• Interleave the bits of the binary values, starting with the first bit of the Y-coordinate: interleaved Y/X = 01101000011000110110001010002

• Interpret the resulting binary value as a base 4 radix integer to get the quadkey string: 01101000011000110110001010002 = 122012031202204 = quadkey string "12201203120220"

We should end up with a quadkey with the same number of digits as the desired tile level, containing only the digits 0-3. Here is the quadkey on the map:

Now, the final step is to encode the tile's logical quadkey as a HEREtile ID.

### HEREtile ID Binary Encoding

To encode a tile logical quadkey string into a packed HEREtile ID, use the following simple algorithm:

Preface the quadkey with a '1': '1' followed by quad-key "12201203120220" = "112201203120220"

Parse an integer value from the resulting string using base 4 radix and convert to base 10 radix: 1122012031202204 = 37789444010 = HEREtile encoded Tile ID: 377894440

This results in a compact binary encoding, when tile IDs up to level 15 can be stored in a 32-bit unsigned integer, and up to level 30 in 64-bit unsigned integer values. In most HERE map products, tiles are published at level 14, so tile IDs are all published as values. Here is an example of map content for that tile: