address_formatter 0.4.0
address_formatter: ^0.4.0 copied to clipboard
Formats address components into human-readable address strings using OpenCage templates for countries worldwide.
Address Formatter #
Overview #
A Dart package for formatting address components into human-readable address strings. It uses the address templates from OpenCage to produce correctly formatted addresses for countries worldwide.
Pass a components map — for example Nominatim's address object (with
addressdetails=1) or Photon's properties.
Installation #
Add the package to your pubspec.yaml:
dependencies:
address_formatter: ^0.4.0
API #
formatAddress(Map<String, dynamic> components, {
String? fallbackCountryCode,
bool appendCountry = true,
bool abbreviate = false,
})
formatAddressSingleLine(Map<String, dynamic> components, {
String? fallbackCountryCode,
bool appendCountry = true,
bool abbreviate = false,
})
formatAddress returns a newline-separated string.
formatAddressSingleLine joins those lines with ', '.
abbreviate: shorten road and place names (Avenue→Ave).appendCountry: include the country name (defaulttrue).fallbackCountryCode: ISO 3166-1 alpha-2 code whencountry_codeis missing.
Use #
print(formatAddress({
'country_code': 'US',
'house_number': '301',
'road': 'Hamilton Avenue',
'neighbourhood': 'Crescent Park',
'city': 'Palo Alto',
'postcode': '94303',
'county': 'Santa Clara County',
'state': 'California',
'country': 'United States',
}));
/*
301 Hamilton Avenue
Palo Alto, CA 94303
United States of America
*/
print(formatAddressSingleLine({
'house_number': '17',
'road': 'Rue du Médecin-Colonel Calbairac',
'postcode': '31000',
'city': 'Toulouse',
'country': 'France',
'country_code': 'FR',
}));
// 17 Rue du Médecin-Colonel Calbairac, 31000 Toulouse, France
License #
This project is licensed under the MIT License. See the LICENSE for details. The OpenCage address templates are also MIT; see THIRD_PARTY_LICENSES.
Contributions #
Contributions welcome.