我的 nodejs 请求不起作用,我错过了什么?

编程入门 行业动态 更新时间:2024-10-05 07:20:12

我的 nodejs 请求<a href=https://www.elefans.com/category/jswz/34/1771377.html style=不起作用,我错过了什么?"/>

我的 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 请求不起作用,我错过了什么?

本文发布于:2024-05-30 10:49:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770416.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   nodejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!