不起作用,我错过了什么?"/>
我的 nodejs 请求不起作用,我错过了什么?
我正在编写一个 Node.js 控制台应用程序,它接收一个 excel 工作表,获取列的值,然后使用这些值调用 Google Maps Geocode 请求以获取纬度和经度,保存它并将新列添加到excel表格。
我有那两个档案
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);
});
那是另一个调用 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;
我不明白为什么它调用 console.log 那是我在调用实际函数之前调用的函数的答案,我错过了什么?
回答如下:更多推荐
我的 nodejs 请求不起作用,我错过了什么?
发布评论