Skip to content

Instantly share code, notes, and snippets.

@danaszova
Created February 9, 2018 05:15
Show Gist options
  • Save danaszova/8e0c0b4d55d69d402bbe6268f2d9ea2d to your computer and use it in GitHub Desktop.
Save danaszova/8e0c0b4d55d69d402bbe6268f2d9ea2d to your computer and use it in GitHub Desktop.
geocoder
exports.geocoder = (ln, cb, key) => {
const { address, city, state } = ln;
const protocol = "https://";
const url = address + "," + city + "," + state;
const api = "maps.googleapis.com/maps/api/geocode/json?address=";
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
const location = JSON.parse(xhr.responseText).results[0].geometry
.location;
cb(location);
}
};
xhr.open("GET", protocol + api + url + key, true);
https: xhr.send(null);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment