Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Current »

This function can be called in the site’s Javascript to determine the location of the visitor of the site.

To be able to call this function, somewhere on the site {% include_plate_scripts "determine_location" %} must be called (e.g. the head section)

The function returns a Javascript Promise, which you can use in the following way:

(() => determineLocation()
  .then(res => console.log(res.country_code))
  .catch(err => console.log(err.message))
)()

The response if successful is a JSON (returned in the then):

{ 
  'country_code': 'NL', 
  'name': 'Netherlands' 
}

The country code is the same as defined in ISO 3166 Standard Country Codes.

If an error occurs (this will be in the catch):

{ 
  'message': '<error message>' 
}

An error is returned in case the network request fails, or if the country could not be determined.

  • No labels