0

I expect this is a noob question. The following works fine:

let maps = require('@google/maps').createClient({ key: '*********' });

exports.getTimeZone = (req, res, next) => {
    maps.geocode({
        address: address
    }, function (err, response) {
        if (err) {
            console.log(err)
        }
        res.json(response);
    });
}

But once I tried to turn it into a simple function it seems to not wait for the response:

function callGoogleGeocode(address) {
    maps.geocode({
        address: address
    }, function (err, res) {
        if (err) {
            console.log(err);
            return err;
        }
        return res;
    });
}

Is there a way to wait for the response without calling a new function from within the call?

EDIT: What you marked me as a duplicate with is for JQuery, which is not what I'm using.

Alex
  • 45
  • 6

0 Answers0