Peter Krauss
Peter Krauss

Reputation: 13920

Where is the algorithm or table that "resolves" the OLC short code?

(contextualizing for those who don't know OLC)

The OLC (Open Location Code) specification is an encoding/decoding algorithm. Similar to Geohash and other geocode specifications, the solution implementing the OLC specification allows you to express a Latitude-Longitude point at the door of a house as the street address of that house. OLC works like a postal code, but pinpointing the door of the house.

Google uses it and offers an API to "resolve" OLC codes into points on a map, and vice versa (points into codes). This is important because it ensures correspondence between addresses and points on Google Maps, using a human-readable code. Some cities, such as Kolkata, are even adopting it as an official "open solution".
PS: an entire country, Cape Verde, tried to adopt it in the past, but ran into the problems of openness that we are discussing in this question.


For example, the point geo:14.9182,-23.5095 represents an address in the region of Praia, Cape Verde. The OLC algorithm converts it to the string 796RWF9R+76. However, 10 characters are difficult for people to remember.

The smart solution suggested by the OLC specification is to replace the code prefix with a "named reference location".

Being able to say WF9R+76, Cape Verde, Praia is significantly easier than remembering 796RWF9R+76.

The string WF9R+76 is shorter, with only 6 characters. It is the "local code", though Google has rebranded it to Plus Code. Here's a summary of string names:

The question

The prefix 796R (of 796RWF9R+76) is derived from the name using the RecoverNearest(shortCode,refPoint) function of the OLC specification. This function, and its inverse (shorten), works by referencing something akin to a lookup table:

Local name Reference Point
... ...
Praia, Cape Verde geo:14.918,-23.509
Joao Varela, Cape Verde geo:14.957,-23.5829
Cruz do Gato, Cape Verde geo:15.0526,-23.5338
... ...

So, the question is: where is the "official lookup table"?
PS: please show the download-link or an "open map reference" (like Geonames, Nominatim etc.) used by Google.


Another way to frame the problem

The Plus Codes presentation page states that it's an open solution, and that works offline.

enter image description here

We can understand that any open source has also some open data, like configurations (a lookup table to configure each city). Thus, Plus Codes is supposed to be open, with a reproducible behaviour. So, another way to express the question is:
  "Where is the source-code of the Local Name Resolver module of Plus Codes?"

Here is the complete decoding algorithm, showing the Name Resolver as a black box:

enter image description here

An official addressing solution for a sovereign country must be open, with no proprietary lock-in. Plus Codes can be a solution, as long as it is reproducible, with no black box involved.

Upvotes: 2

Views: 564

Answers (2)

dericke
dericke

Reputation: 304

There cannot be a simple lookup table relating cities to prefixes, because many cities can match more than one prefix. Take the example of Manaus, Amazonas, Brazil:

screenshot of plus.codes/map showing the city of Manaus, Brazil overlaid by 4 grid squares, labeled 679X, 6892, 678X, and 6882 Screenshot from https://plus.codes/map

Downtown Manaus is in grid cell 678X, but a significant portion of the city is in cell 6882, with smaller portions in cells 679X and 6892. There's no way for a lookup table to resolve an input like W2VJ+GC Manaus, State of Amazonas, Brazil using only a table, because that would result in four possibilities: 679XW2VJ+GC, 6892W2VJ+GC, 678XW2VJ+GC, or 6882W2VJ+GC.

Instead, according to the reference implementations in various languages, a short code is resolved to a full open location code in two steps:

  1. Geocode the city component to a latitude and longitude
  2. Pass the latitude and longitude, along with the short code, to the recoverNearest function, and receive the full Open Location Code back

The reference library leaves the details of geocoding to the developer. Because geocoding is a fairly complicated and difficult problem, many commercial services exist—the Python library geopy has a fairly extensive list of geocoders it supports, many of which are paid, but some of which are free with restrictions. Geocoding down to the city level is easier than geocoding addresses and business names, and it might be feasible to build your own geocoder using something like OSMNames. Nominatim is a fairly popular open-source geocoder that can be examined and self-hosted, if you want to learn more about their workings.

Google's own implementation of Open Location Codes in their own applications can be assumed to use their own geocoder. Their geocoder is indeed a black box, but open alternatives like Nominatim exist, so a fully open-source implementation of Open Location Codes is possible.

Upvotes: 0

Alexander Ushakov
Alexander Ushakov

Reputation: 5389

Open Location Code is just another form of standard geographic coordinate: latitude and longitude. So, to get OLC for any place you need only geo coordinates for this place (see encoding section) and vice versa.

With database of Cape Verde towns and their coordinates you can build your own lookup table for quick OLC transformation with any required precision (starting from Wikipedia List of cities and towns in Cape Verde or using any of free world cities databases) or you can just convert OLC to latitude and longitude and than work with this coordinates.

Upvotes: 0

Related Questions