❯ Guillaume Laforge

Exploring Open Location Code

When using Google Maps, you might have seen those strange little codes, as in the screenshot above. This is a plus code, or to use the more official name, an Open Location Code. It’s a way to encode a location in a short and (somewhat) memorable form.

In countries like France, every house has an official address, so you can easily receive letters or get some parcel delivered. But there are countries where no such location system exists, so you have to resort to describing where you live (take this road, turn right after the red house, etc.)

Of coursse, you could use GPS coordinates, but that’s not very convenient to share, and nobody could remember a precise address. So there have been several attemps at creating systems that represent any location in the world, like GeoHash, MapCode, and other proprietary systems like 3-words.

Out of curiosity, I wanted to play with this geo-encoding approach, and decided to spend a few minutes playing with the available Java library (available on Maven Central), but using Apache Groovy.

You’ll find more links on the topic at the end of this article.

Playing with plus codes in Groovy

Here’s a little script that shows the library in action:

@Grab("com.google.openlocationcode:openlocationcode:1.0.4")
import com.google.openlocationcode.OpenLocationCode

// Eiffel Tower
def (lat, lon) = [48.8584, 2.29447]

def eiffelTowerPlusCode = OpenLocationCode.encode(lat, lon)
println "Eiffel Tower +code: ${eiffelTowerPlusCode}"

def decoded = OpenLocationCode.decode('8FW4V75V+9Q')
println "Original coord: ${decoded.centerLatitude}, ${decoded.centerLongitude}"

(You can play and run the above script in the Groovy Web Console)

More information