Address Reverse Geocoding (NZ only)
The Address Reverse Geocoding service takes GPS coordinates (longitude and latitude) to find and return addresses near to the coordinates. This is often the users phone or computer GPS coordinates. This is an interactive search service where the response returns a list of addresses for the user to select from.
This service is only available in New Zealand.
Widget integration guide
Address Reverse Geocoding is most commonly used alongside the Address Autocomplete service, allowing users to choose to search their address either by typing it into the search field or allowing their browser to share their position. Due to this, code snippet below includes both Reverse Geocode and Address Autocomplete services.
This page outlines how to integrate the Address Reverse Geocode Widget.
For advanced integration utilise the Address Reverse Geocode API and Address Metadata API.
How to integrate
You’ll need access to update the website or form where you want to add the widget and have an Addressfinder account.
- Copy and paste the code snippet below into the HTML of your webpage, ideally just before the closing
</body>
tag. - Replace
search_field_id
(placeholder) with the ID of your first address field (eg, address_1). - Replace
your_license_key
with your Addressfinder license key. You can find it in the Addressfinder Portal. If you don't have an Addressfinder account, sign up for a free trial. - Update the code snippet with the IDs of the fields you are using to capture the selected address. This needs to be twice so as to handle addresses selected from both the address autocomplete response and the reverse geocode response.
- Test.
Reverse Geocode and Address Autocomplete code snippet
<script>
(function() {
var widget, initAddressFinder = function() {
widget = new AddressFinder.Widget(
// Step 2 - Replace 'search_field_id' with the ID of your POI search field.
document.getElementById('search_field_id'),
// Step 3 - Replace `your_license_key` with your Addressfinder license key.
'your_license_key',
'NZ', {
"address_params": {},
"show_nearby": true
}
);
// Step 4 - Update the lines below with the IDs of the fields you want the information to be populated into.
widget.on('address:select', function(fullAddress, metaData) {
document.getElementById('address_line_1_field_id').value = metaData.address_line_1;
document.getElementById('address_line_2_field_id').value = metaData.address_line_2 || '';
document.getElementById('suburb_field_id').value = metaData.selected_suburb;
document.getElementById('city_field_id').value = metaData.selected_city;
document.getElementById('postcode_field_id').value = metaData.postcode;
});
// Step 4 (repeated) - Update the lines below with the IDs of the fields you want the information to be populated into.
widget.on('result:select', function(fullAddress, metaData) {
let selected = new AddressFinder.NZSelectedAddress(fullAddress, metaData);
document.getElementById('address_line_1_field_id').value = selected.address_line_1();
document.getElementById('address_line_2_field_id').value = selected.address_line_2() || '';
document.getElementById('suburb_field_id').value = selected.suburb();
document.getElementById('city_field_id').value = selected.city();
document.getElementById('postcode_field_id').value = selected.postcode();
});
};
function downloadAddressFinder() {
var script = document.createElement('script');
script.src = 'https://api.addressfinder.io/assets/v3/widget.js';
script.async = true;
script.onload = initAddressFinder;
document.body.appendChild(script);
};
document.addEventListener('DOMContentLoaded', downloadAddressFinder);
})();
</script>
Metadata Response
The metadata available, when a user selects an address returned in the reverse geocode autocomplete responce, is the same as the data returned when an address in the address autocomplete response is selected. View metadata returned here.