I am writting a Node.js console application that , receives an excel sheet, gets the values of a column, then with those values i call a Google Maps Geocode request to get the Latitude and Longitude, save it and add new columns to the excel sheet.
I have those two archives
const ExcelJS = require('exceljs');
// Ler o Excel existente e pegar os ceps
const wb = new ExcelJS.Workbook();
const fileName = 'NovoExcel.xlsx';
var ceps = [];
wb.xlsx.readFile(fileName).then(() => {
const ws = wb.getWorksheet('Planilha1');
const c1 = ws.getColumn(1);
c1.eachCell(c => {
ceps.push(c.value);
});
console.log(ceps);
var mapsFunc =require("./maps")
var coordenadas = mapsFunc(ceps);
console.log(coordenadas)
}).catch(err => {
console.log(err.message);
});
Thats the other archive which calls the Api
const {Client} = require("@googlemaps/google-maps-services-js");
var maps = function(ceps){
var Latitude = [];
var Longitude = [];
ceps.forEach(element => {
const args = {
params: {
key: 'AIzaSyA5_Hox6vhpLt3kRpqxr_0eXBUssHIva7g',
address: element + ' br ',
}
};
const client = new Client();
client.geocode(args).then(gcResponse => {
Latitude.push(gcResponse.data.results[0].geometry.location.lat)
Longitude.push(gcResponse.data.results[0].geometry.location.lng)
console.log(Latitude)
});
});
return [Latitude,Longitude]
}
module.exports = maps;
I dont understand why it calls the console.log thats the answer of the function i call before it calls the actual function, what am i missing?