Skip to content

Instantly share code, notes, and snippets.

@kameshsampath
Last active February 23, 2018 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kameshsampath/bc47f23e885b4e282557b6a42b9936f1 to your computer and use it in GitHub Desktop.
Save kameshsampath/bc47f23e885b4e282557b6a42b9936f1 to your computer and use it in GitHub Desktop.
The working version of the api
'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,
Promise: Promise
})
return gmapClient.reverseGeocode({
"latlng": latlng,
"result_type": "postal_code"
}).asPromise()
.then((response) => {
let status = response.json.status
let location = ""
if (status === 'OK') {
location = response.json.results[0].formatted_address
}
return { status: status, location: location }
}).catch((err) => {
console.log("Err: ", err)
return { status: err, location: "unknown" }
})
}
global.main = location;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment