Create a .env file and add a GOOGLE_MAPS_API_KEY variable:
GOOGLE_MAPS_API_KEY=AIz...ezIInstall stuff:
npm installnode example.jsGive places-to-coords an array of strings and a callback.
The callback will be called every time a response is received.
const placesToCoords = require('./places-to-coords');
const placeNames = [ 'Germany', 'Arlington, VA' ];
const callback = (err, data) => console.log('Got one.', data)
placesToCoords(placeNames, callback);The response data will look like this:
{
address: 'New York, NY',
location: {
lat: 40.7127837,
lng: -74.0059413
}
}A Promise is also returned once all the results are collected:
const placesToCoords = require('./places-to-coords');
const placeNames = [ 'Germany', 'Arlington, VA' ];
placesToCoords(placeNames)
.then(results => {
console.log("We're all done here.", results);
});Note: The order of responses will not match the order of addresses in the array.