Skip to content

Address Formatter Kotlin

Did you know having the house number displayed after the street name is not common in all parts of the world? (speaking here from a European mainland perspective)

While setting up sequences and routing drivers all over the world, we learned that language and operational processes aren't the only things that differ by country: address formatting does too. We investigated the existing options and found them mostly stale, so we built and open-sourced our own: Address Formatter Kotlin, free to use under the Apache 2.0 license.

When you need this

The Better Route API and Bettermile Driver App return addresses as individual components, such as street, house number, and postal code, not a single formatted string. If you only operate in a single country, you likely don't need this library; you can just hard-code the component order yourself. If you serve multiple countries, though, the expected order and conventions differ per country, and that's what this library handles for you.

Installation

// Gradle (Kotlin DSL)
implementation("com.bettermile:address-formatter-kotlin:<latest-version>")
<!-- Maven -->
<dependency>
  <groupId>com.bettermile</groupId>
  <artifactId>address-formatter-kotlin</artifactId>
  <version>latest-version</version>
</dependency>

The library ships as Kotlin Multiplatform (JVM and iOS), with no runtime dependency beyond the Kotlin standard library. Check the repository for the current version and language/tooling requirements.

Usage

val formatter = AddressFormatter(abbreviate = false, appendCountry = false)
val components = mapOf(
    "country_code" to "US",
    "house_number" to "301",
    "road" to "Hamilton Avenue",
    "city" to "Palo Alto",
    "postcode" to "94303"
)
println(formatter.format(components))

Source and license

The library is open source under the Apache 2.0 license: github.com/bettermile/address-formatter-kotlin.