Home

Awesome

Address Formatter

A library for formatting addresses.

Overview

This project uses the address templates from OpenCage to format addresses.

This library has only the kotlin standard library and Mustache.java (needed to format the address template) as dependencies.

For Java 11 and above.

Installation

Add the library to your dependencies.

Gradle (Kotlin)

dependencies {
    implementation("com.bettermile:address-formatter-kotlin:0.3.3")
}

Gradle (Groovy)

dependencies {
    implementation 'com.bettermile:address-formatter-kotlin:0.3.3'
}

Maven

<dependency>
  <groupId>com.bettermile</groupId>
  <artifactId>address-formatter-kotlin</artifactId>
  <version>0.3.3</version>
</dependency> 

Usage

val formatter = AddressFormatter(abbreviate = false, appendCountry = false)
val components = mapOf(
    "country_code" to "US",
    "house_number" to "301",
    "road" to "Hamilton Avenue",
    "neighbourhood" to "Crescent Park",
    "city" to "Palo Alto",
    "postcode" to "94303",
    "county" to "Santa Clara County",
    "state" to "California",
    "country" to "United States",
)
println(formatter.format(components))
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/

val abbreviateFormatter = AddressFormatter(abbreviate = true, appendCountry = false)

println(abbreviateFormatter.format(json))
/*
301 Hamilton Ave
Palo Alto, CA 94303
United States of America
*/

val appendCountryFormatter = AddressFormatter(abbreviate = false, appendCountry = true)
println(appendCountryFormatter.format(json))
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/

License

This project is licensed under the Apache 2.0. See the LICENSE for details.

Acknowledgements