Created
February 23, 2018 05:30
-
-
Save kameshsampath/efcf46fdf190befe83e6f3ffc9266a40 to your computer and use it in GitHub Desktop.
This you should not do
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
'use strict'; | |
const gmap = require('@google/maps'); | |
function location(params) { | |
const latlng = JSON.parse(JSON.stringify(params.coords)) | |
const gmapClient = gmap.createClient({ | |
key: process.env.GOOGLE_MAPS_API_KEY | |
}) | |
return new Promise(function (resolve, reject) { | |
gmapClient.reverseGeocode({ | |
"latlng": latlng, | |
"result_type": "postal_code" | |
}, function (results, status) { | |
let respStatus = response.json.status | |
if (respStatus === 'OK') { | |
resolve({ status: respStatus, location: response.json.results[0].formatted_address }) | |
} else { | |
reject({ status: respStatus, location: "" }) | |
} | |
}) | |
}); | |
} | |
global.main = location; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment