Home

Awesome

Address Formatter

Overview

A Maven package for formatting data in the OpenStreetMaps address field generated by the Nominatim API. This project was only possible thanks to the amazing OpenCage team, who did the work of collating the postal address formats upon which this library relies.

For Java 8 and above.

Installation

Add the following to your pom.xml to use the latest release with Maven:

<dependency>
  <groupId>net.placemarkt</groupId>
  <artifactId>address-formatter-java</artifactId>
  <version>0.0.10</version>
</dependency> 

API

// Constructor
AddressFormatter(Boolean abbreviate, Boolean appendCountry)

// Methods
format(String json)
format(String json, String fallbackCountryCode)

Use

AddressFormatter formatter = new AddressFormatter(false, false);
String json = "{country_code: 'US',\n"
          + "house_number: '301',\n"
          + "road: 'Hamilton Avenue',\n"
          + "neighbourhood: 'Crescent Park',\n"
          + "city: 'Palo Alto',\n"
          + "postcode: '94303',\n"
          + "county: 'Santa Clara County',\n"
          + "state: 'California',\n"
          + "country: 'United States',}";
String formatted = formatter.format(json);
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/

AddressFormatter abbreviateFormatter = new AddressFormatter(true, false);
String json = "{country_code: 'US',\n"
          + "house_number: '301',\n"
          + "road: 'Hamilton Avenue',\n"
          + "neighbourhood: 'Crescent Park',\n"
          + "city: 'Palo Alto',\n"
          + "postcode: '94303',\n"
          + "county: 'Santa Clara County',\n"
          + "state: 'California',\n"
          + "country: 'United States',}";
String formatted = abbreviateFormatter.format(json);
/*
301 Hamilton Ave
Palo Alto, CA 94303
United States of America
*/

AddressFormatter appendCountryFormatter = new AddressFormatter(false, true);
String json = "{country_code: 'US',\n"
          + "house_number: '301',\n"
          + "road: 'Hamilton Avenue',\n"
          + "neighbourhood: 'Crescent Park',\n"
          + "city: 'Palo Alto',\n"
          + "postcode: '94303',\n"
          + "county: 'Santa Clara County',\n"
          + "state: 'California',}"
String formatted = appendCountryFormatter.format(json);
/*
301 Hamilton Ave
Palo Alto, CA 94303
United States of America
*/

License

This project is licensed under the MIT License. See the LICENSE for details.

Contributions

Contributions welcome. Be nice.

Acknowledgements