Created
February 22, 2016 08:53
-
-
Save vicchi/6ea0c7cf1fd42d20d0d8 to your computer and use it in GitHub Desktop.
what3words API authentication with XMLHttpRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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