Created
February 9, 2018 05:15
-
-
Save danaszova/8e0c0b4d55d69d402bbe6268f2d9ea2d to your computer and use it in GitHub Desktop.
geocoder
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
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