Loading...
Sign in to see the examples with your own API key.

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.

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.

Top