Google Places fallback
LINZ's NZ Addresses data holds addresses but no business names, so someone typing a shop's or a building's name finds nothing. Switch on the free Google Places fallback and, only when no address is found, the JavaScript Autocomplete searches Google for businesses and places with your own Google API key, straight from the visitor's browser. Addresses always come from LINZ data; Google is only asked for establishments.
- Switch it on, and paste your key, on the Add-ons tab of your console. It applies to every domain token on that subscription, and reaches your pages within a few minutes. Nothing changes in your page code.
- It only runs with a domain token. An API key used from a server never gets a fallback.
- Google bills your Google Cloud account. We don't charge for it, and a Google result never counts as a look-up.
- Restrict the key in Google Cloud: allow only your websites, and only the Maps JavaScript API and Places API (New). The key is sent to visitors' browsers.
- Google results are listed with the text Google Maps beneath them, as Google's terms require. Keep it visible if you restyle the list.
- The widget loads the Maps JavaScript API from
maps.googleapis.comthe first time it is needed. If your site has a Content Security Policy, allowmaps.googleapis.comandmaps.gstatic.com; if it can't load, the fallback reports an error and the field carries on as before.
What a Google pick looks like
A picked Google place fills your form from Google's own address parts. It is not a LINZ address, so it has no
LINZ address_id to store and pass to Get later. The picked suggestion's
provider is 'google'; check it before keeping an id.
input.addEventListener('getaddress-nz-autocomplete-address-selected', e => {
if (e.suggestion.provider === 'google') {
// Not a LINZ address: there is no address_id to keep.
}
});
Keeping one page on LINZ addresses only
Pass google_places_fallback: false to the JavaScript Autocomplete on that page.
getAddressNz.autocomplete('address', '{your-domain-token}', { google_places_fallback: false });
In the API
The Autocomplete response carries your key as fallback when a domain-token request finds no suggestions.