
Pure Open Location Code implementation to encode, decode, shorten, recover and validate Plus Codes. Strong type-safety via zero‑overhead value type; passes official Google test vectors.
This is a pure Kotlin Multiplatform (KMP) port of Google's Open Location Code, also known as Plus Codes.
Open Location Code is a technology that gives a way of encoding location into a format that is easier to use than latitude and longitude.
Attribution: This library is a direct Kotlin port of the original Java implementation maintained by Google. The core logic, constants, and math were derived from the official Google open-location-code repository, and are used under the Apache License, Version 2.0. See
NOTICEfor the full attribution.
Google does not take language ports into the main repository. When a Kotlin Multiplatform port was proposed in google/open-location-code#366 — open from 2019 until it was closed in 2024 — the maintainers were explicit:
This is great work but unfortunately we're struggling to support the implementations we already have. If you can publish it to your own repo, please add a link in External_Implementations.md.
Publishing independently is therefore the arrangement Google asked for, not a fork around them.
commonMain source set. No expect/actual platform wrappers required.value class to represent the PlusCode string, providing strong type-safety without memory overhead.You can add this library to your KMP, Android, or JVM project by declaring the dependency in your build.gradle.kts:
dependencies {
implementation("io.github.aughtone:openlocationcode:0.0.2")
}For native Swift development, this library is distributed as a precompiled XCFramework.
https://github.com/aughtone/aughtone-openlocationcode
-alpha1, select Exact Version.)
OpenLocationCode product to your target.The API is intentionally similar to the original Google library, modernized for Kotlin.
To encode a latitude and longitude into a Plus Code:
import io.github.aughtone.openlocationcode.OpenLocationCode
// Encode with default precision (10 digits)
val code = OpenLocationCode.encode(47.365590, 8.524997)
println(code.value) // Output: 8FVC9G8F+6X
// Encode with specified code length
val preciseCode = OpenLocationCode.encode(47.365590, 8.524997, 11)
println(preciseCode.value) // Output: 8FVC9G8F+6XWTo decode a Plus Code back into a bounding box (CodeArea):
import io.github.aughtone.openlocationcode.OpenLocationCode
import io.github.aughtone.openlocationcode.PlusCode
val plusCode = PlusCode("8FVC9G8F+6X")
val area = OpenLocationCode.decode(plusCode)
println("Center Latitude: ${area.centerLatitude}")
println("Center Longitude: ${area.centerLongitude}")
println("Southwest Corner: ${area.southLatitude}, ${area.westLongitude}")If you know the user's current location, you can shorten a Plus Code by dropping the region characters:
val fullCode = PlusCode("8FVC9G8F+6X")
val referenceLat = 47.365590
val referenceLng = 8.524997
val shortCode = OpenLocationCode.shorten(fullCode, referenceLat, referenceLng)
println(shortCode.value) // Output: 9G8F+6XTo expand a short code back to a full code using a reference location:
val shortCode = PlusCode("9G8F+6X")
val referenceLat = 47.365590
val referenceLng = 8.524997
val recoveredCode = OpenLocationCode.recoverNearest(shortCode, referenceLat, referenceLng)
println(recoveredCode.value) // Output: 8FVC9G8F+6XYou can validate strings to see if they are structurally sound Plus Codes:
val isValid = OpenLocationCode.isValidCode("8FVC9G8F+6X") // true
val isFull = OpenLocationCode.isFullCode("8FVC9G8F+6X") // true
val isShort = OpenLocationCode.isShortCode("9G8F+6X") // trueThis project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
This is a pure Kotlin Multiplatform (KMP) port of Google's Open Location Code, also known as Plus Codes.
Open Location Code is a technology that gives a way of encoding location into a format that is easier to use than latitude and longitude.
Attribution: This library is a direct Kotlin port of the original Java implementation maintained by Google. The core logic, constants, and math were derived from the official Google open-location-code repository, and are used under the Apache License, Version 2.0. See
NOTICEfor the full attribution.
Google does not take language ports into the main repository. When a Kotlin Multiplatform port was proposed in google/open-location-code#366 — open from 2019 until it was closed in 2024 — the maintainers were explicit:
This is great work but unfortunately we're struggling to support the implementations we already have. If you can publish it to your own repo, please add a link in External_Implementations.md.
Publishing independently is therefore the arrangement Google asked for, not a fork around them.
commonMain source set. No expect/actual platform wrappers required.value class to represent the PlusCode string, providing strong type-safety without memory overhead.You can add this library to your KMP, Android, or JVM project by declaring the dependency in your build.gradle.kts:
dependencies {
implementation("io.github.aughtone:openlocationcode:0.0.2")
}For native Swift development, this library is distributed as a precompiled XCFramework.
https://github.com/aughtone/aughtone-openlocationcode
-alpha1, select Exact Version.)
OpenLocationCode product to your target.The API is intentionally similar to the original Google library, modernized for Kotlin.
To encode a latitude and longitude into a Plus Code:
import io.github.aughtone.openlocationcode.OpenLocationCode
// Encode with default precision (10 digits)
val code = OpenLocationCode.encode(47.365590, 8.524997)
println(code.value) // Output: 8FVC9G8F+6X
// Encode with specified code length
val preciseCode = OpenLocationCode.encode(47.365590, 8.524997, 11)
println(preciseCode.value) // Output: 8FVC9G8F+6XWTo decode a Plus Code back into a bounding box (CodeArea):
import io.github.aughtone.openlocationcode.OpenLocationCode
import io.github.aughtone.openlocationcode.PlusCode
val plusCode = PlusCode("8FVC9G8F+6X")
val area = OpenLocationCode.decode(plusCode)
println("Center Latitude: ${area.centerLatitude}")
println("Center Longitude: ${area.centerLongitude}")
println("Southwest Corner: ${area.southLatitude}, ${area.westLongitude}")If you know the user's current location, you can shorten a Plus Code by dropping the region characters:
val fullCode = PlusCode("8FVC9G8F+6X")
val referenceLat = 47.365590
val referenceLng = 8.524997
val shortCode = OpenLocationCode.shorten(fullCode, referenceLat, referenceLng)
println(shortCode.value) // Output: 9G8F+6XTo expand a short code back to a full code using a reference location:
val shortCode = PlusCode("9G8F+6X")
val referenceLat = 47.365590
val referenceLng = 8.524997
val recoveredCode = OpenLocationCode.recoverNearest(shortCode, referenceLat, referenceLng)
println(recoveredCode.value) // Output: 8FVC9G8F+6XYou can validate strings to see if they are structurally sound Plus Codes:
val isValid = OpenLocationCode.isValidCode("8FVC9G8F+6X") // true
val isFull = OpenLocationCode.isFullCode("8FVC9G8F+6X") // true
val isShort = OpenLocationCode.isShortCode("9G8F+6X") // trueThis project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.