Last active
February 23, 2018 05:38
-
-
Save kameshsampath/bc47f23e885b4e282557b6a42b9936f1 to your computer and use it in GitHub Desktop.
The working version of the api
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, | |
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