Created
April 21, 2017 21:19
-
-
Save tjunxiang92/1050bb03af2801e853a082ee8513b90e to your computer and use it in GitHub Desktop.
Translate Address into lat lng
This file contains 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
// Geocoding | |
// https://developers.google.com/maps/documentation/geocoding/intro | |
const API_KEY = "Fetch from google: https://developers.google.com/maps/documentation/javascript/get-api-key"; | |
const address = "Here is your address"; | |
const decodeLatLng = address => { | |
return new Promise((resolve, reject) => { | |
request(`https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${API_KEY}`, | |
(error, response, body) => { | |
if (error) reject(error); | |
let decoded = JSON.parse(body); | |
let latlng = decoded.results[0].geometry.location; | |
resolve(latlng); | |
}); | |
}); | |
}; | |
// Prints out the decoded latlng | |
decodeLatLng(address).then(latlng => console.log(latlng); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment