Skip to content

Instantly share code, notes, and snippets.

@vicchi
Created February 22, 2016 08:53
Show Gist options
  • Save vicchi/6ea0c7cf1fd42d20d0d8 to your computer and use it in GitHub Desktop.
Save vicchi/6ea0c7cf1fd42d20d0d8 to your computer and use it in GitHub Desktop.
what3words API authentication with XMLHttpRequest
function loadConfig(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', './config.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
}
};
xobj.send(null);
}
function init() {
loadConfig(function(response)) {
json = JSON.parse(response);
}
}
var json = {};
init();
var key = json.what3words.key;
var options = {
key: key
lang: 'en'
};
var w3w = new What3words(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment