Integrations
Run any Addy API live with Addy Swagger UI on us for free with 'demo-api-key' API key
This is a step-by-step guide to add an address autocomplete widget onto a website within minutes using lightweight open source JavaScript code. A range of address form combinations are covered to demonstrate how to simplify and speed up a checkout / registration form by auto-suggesting addresses while users type.
Address validation happens in real-time by calling Addy's address finder API to find addresses and ensuring address fields are complete and accurate with suburb, city and postcode.
Contact us if you need help and we will be happy to assist.
Use the JavaScript Code Generator for fast and easy address autocomplete integration.
This demo caters for a typical scenario where two address lines are available on a registration or checkout form.
This demo caters for multiple address fields on a single page such as a billing and shipping address form. It is recommended to simplify the order page with an option to use the same billing and shipping address to improve checkout efficiency.
In this demo, address suggestions will only show up when the selected country is New Zealand.
This section describes how to assign address fields to a web form by using the JavaScript address lookup widget.
Only the "input" address field parameter as defined in the first constructor parameter is mandatory. Fields can be passed into the second constructor parameter or defined through the fields property.
<script type="text/javascript">
// Address Autocomplete Instance
var addyComplete = new AddyComplete(document.getElementById("address1"));
// Map the fields to address controls
addyComplete.fields = {
address1: document.getElementById("address1"),
address2: document.getElementById("address2"),
...
}
</script>
The supported address fields are defined below:
Name | Description | JSON Mapping |
---|---|---|
address | The display name of the address | displayline |
address1 | Address line 1. Often used in combination with address2 | address1 |
address2 | Address line 2. Often used in combination with address1 | address2 |
suburb | The name of the suburb | suburb |
city | The name of the city or mail town | city |
territory | The name of the territory. See districts of New Zealand | territory |
region | The name of the region. See regions of New Zealand | region |
postcode | The postal code | postcode |
line1 | Address Line 1 | address1 |
line2 | Address Line 2 | address2 |
line3 | Address Line 3 | address3 |
line4 | Address Line 4 | address4 |
This section describes the address fields that will be populated when an address is selected.
Examples:
Single Address Field
address | suburb | city | region | postcode |
---|---|---|---|---|
Floor 23, 151 Queen Street | Auckland Central | Auckland | Auckland | 1010 |
1 Fitzroy Road | Bluff Hill | Napier | Hawke's Bay | 4110 |
115 Ngarongo Road, RD 13 | <Empty> | Hawera | Taranaki | 4673 |
PO Box 1 | <Empty> | Taupo | Waikato | 3351 |
Two Address Fields
address 1 | address 2 | suburb | city | postcode |
---|---|---|---|---|
Floor 23 | 151 Queen Street | Auckland Central | Auckland | 1010 |
1 Fitzroy Road | <Empty> | Bluff Hill | Napier | 4110 |
115 Ngarongo Road | RD 13 | <Empty> | Hawera | 4673 |
PO Box 1 | <Empty> | <Empty> | Taupo | 3351 |
Four Address Fields
line 1 | line 2 | line 3 | line 4 |
---|---|---|---|
Floor 23 | 151 Queen Street | Auckland Central | Auckland 1010 |
1 Fitzroy Road | Bluff Hill | Napier 4110 | <Empty> |
115 Ngarongo Road | RD 13 | Hawera 4673 | <Empty> |
PO Box 1 | Taupo 3351 | <Empty> | <Empty> |
Two Address Field - No Suburb Field
address 1 | address 2 | city | postcode |
---|---|---|---|
Floor 23, 151 Queen Street | Auckland Central | Auckland | 1010 |
1 Fitzroy Road | Bluff Hill | Napier | 4110 |
115 Ngarongo Road | RD 13 | Hawera | 4673 |
PO Box 1 | <Empty> | Taupo | 3351 |
The example below shows the options that are available as URL parameters:
<script src="https://www.addysolutions.com/address-lookup/1.6.2/js/addy.min.js?nzKey=demo-api-key&country=nz&callback=initAddy&excludePostBox=false&excludeRural=false&excludeUndeliver=false&excludeSpelling=false&excludeWord=false&excludeIp=false&maxItems=10&loadcss=true&enableLocation=true&excludePostcode=0622-1010&includePostcode=0622-1010&excludeRegion=1-2&includeRegion=3-4&excludeTerritory=1-2-3&includeTerritory=5-6-7&tag=sales&uniqueid=12345" async defer></script>
URL Parameter | Default Value | Description |
---|---|---|
key | N/A | Addy API Key |
callback | N/A | An optional callback method name that should be executed when the addycomplete script has loaded |
excludePostBox | false | Exclude PO Boxes and Private Bag addresses |
excludeRural | false | Exclude rural addresses |
excludeUndeliver | false | Exclude non-mail delivery addresses |
excludeSpelling | false | Disable spelling correction from address matching |
excludeWord | false | Disable extra word removal from address matching |
excludeIp | false | Disable address sorting based on IP address proximity |
excludePostcode | Exclude addresses within certain postcodes, defined in a dash separated list of postcodes E.g. "1010-0622-7542". See the complete list of postcodes filters | |
includePostcode | Only include addresses within certain postcodes, defined in a dash separated list of postcodes. E.g. "1010-0622-7542". See the complete list of postcodes filters | |
excludeRegion | Exclude addresses within certain regions, defined in a dash separated list of region codes E.g. "1-2-6" for Northland, Auckland and Taranaki. See the complete list of region code filters | |
includeRegion | Only include addresses within certain regions, defined in a dash separated list of region codes E.g. "1-2-6" for Northland, Auckland and Taranaki. See the complete list of region code filters | |
excludeTerritory | Exclude addresses within certain territories, defined in a dash separated list of territory codes E.g. "22-14" for Kapiti Coast District and Hamilton City. See the complete list of territory code filters | |
includeTerritory | Only include addresses within certain territories, defined in the dash separated list of territory codes E.g. "22-14" for Kapiti Coast District and Hamilton City. See the complete list of territory code filters | |
tag | Add a logging tag to every request E.g. A department name such as "Sales" | |
uniqueid | Add a unique Identifier to every request E.g. An internal customer ID such as "12345" | |
maxItems | 10 | An optional parameter to specify the maximum number of address items to return |
loadcss | false | Load the default addycomplete.min.css stylesheet |
enableLocation | false | Enable reverse geocoding to return "Addresses near me" |
URL parameters can be used as discussed above, which would apply the options to all of the address control instances on the page. The example below shows how to configure options in JavaScript for the addressComplete instance:
Property | Default Value | Description |
---|---|---|
options.excludePostBox | false | An optional parameter to exclude PO Boxes and Private Bag numbers from the address results. |
options.maxItems | 10 | Maximum number of address suggestions to display. |
The example below shows how to register for the "address selected" event to enable full control over how to render and populate address fields on your website.
View the Address Details API documentation to learn more about the available address properties.
Use the CSS stylesheet elements below to control the theme, such as the colours and fonts, that will match your brand.
Use the JavaScript below to modify the CSS class names or to change the content of the messages.
The code used in these examples, including third party dependencies (reqwest and neat-complete) are open source and available on GitHub.
There are no dependencies on heavy weight libraries such as jQuery and jQuery UI .
Address Services
Address AutocompleteAddress CleansingAddress GeocodingPostcode FinderPricingSign inSign upAddress APIs
Address Finder APIAddress Validation APIAddress Details APIAddress Discovery APIPostcode Finder APIGeocode Address APIBounding Box API