A map tile as a 64-bit integer¶
I want to know where users are, and I do not want to know where users are.
Both are true. Aggregates by area are useful: how many, where, when. An exact position per user is a liability. It is sensitive, and once it is stored it has to be protected for as long as it exists.
A quadkey solves most of this. It comes from the Bing Maps tile system. The world is one square, split in four, and each of those in four again. Every split adds one digit from 0 to 3, so a position at zoom level 18 is a string of 18 digits:
final Coordinate c = new Coordinate(40.757678, -73.969558);
QuadKey qk = new QuadKey(c, 18); // about 0.6 m per pixel
qk.getAsString(); // "032010110132031203"
qk.getAsLong(); // 15104861027
Two things follow from how it is built.
A tile's key is a prefix of every tile inside it. So "is this point inside that square" is a prefix check, and on the integer form it is plain arithmetic. That makes it a good database index. A range scan on one indexed column finds everything in an area, with no spatial extension.
And the precision is something you choose. Cut the key at a lower zoom level and the position becomes a square of a few hundred meters, or a few kilometers. You store the square. The exact position is never written down, so it cannot leak later.
That is the part I like. It is not anonymisation, and I will not call it that. A square with one person in it is still that person. But it lets me decide the resolution up front, and keep what the aggregate needs and no more.
jquad is a small Java library for this. Each digit takes 2 bits, so a key fits in a 64-bit integer with room to spare.