Google Places fallback
DAR has every address in Denmark but no business names, so someone typing Tivoli finds nothing. Switch on the free Google Places fallback and, only when DAR finds nothing, the JavaScript Autocomplete searches Google for businesses and places in Denmark with your own Google API key, straight from the visitor's browser. Addresses always come from DAR; Google is only asked for establishments.
- Switch it on, and paste your key, on the Tilvalg 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 (HTTP referrers), 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 (
.getaddress-dk-autocomplete__attribution). - 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. - It needs
getaddress-dk-autocomplete1.2.0 or later. DAWA's own dawa-autocomplete2 knows nothing of it.
What a Google pick looks like
A picked Google place reaches your select the way a DAR address does: valgt.tekst is the
address on one line and valgt.data has DAWA's field names, filled from what Google says —
vejnavn, husnr, postnr, postnrnavn, and
x/y as longitude and latitude (empty with srid=25832). Two fields are
added: cleaning_provenance {"Source": "GOOGLE"} and navn, the place's
name. Everything only DAR knows — id, vejkode, kommunekode,
adgangsadresseid, href — is empty. Check cleaning_provenance
before storing an id to pass to Adresser later.
getAddressDk.autocomplete('adresse', '{your-domain-token}', {
select(valgt) {
if (valgt.data.cleaning_provenance?.Source === 'GOOGLE') {
// Not in DAR: there is no id to keep.
}
}
});
Keeping one page on DAR only
Pass googlePlacesFallback: false to the JavaScript Autocomplete on that page.
getAddressDk.autocomplete('adresse', '{your-domain-token}', { googlePlacesFallback: false });
In the API
DAWA's /autocomplete answers exactly as DAWA did, add-on or not. When its answer is
empty, the widget asks GET /fallback with the same parameters (the token rides in the path as for
autocomplete, https://api.getaddress.dk/t/{your-domain-token}/fallback?q=…). It is free and rate limited, and
answers 200 with your key only when the request came on a domain token, the add-on is on, and the same
autocomplete finds nothing:
{
"provider": "google_places",
"key": "AIza…"
}
Anything else is 204 No Content.