【问题标题】:NodeJS Request Module Google Maps GeoCode API PostNodeJS 请求模块 Google Maps GeoCode API Post
【发布时间】:2017-01-17 00:11:15
【问题描述】:

我编写了一个函数,该函数使用request module 通过 POST 方法调用Google Maps Geocode API,该方法将进一步修改为返回所提供地址的纬度和经度。

但是,它现在返回错误:

Hostname/IP doesn't match certificate's altnames: "Host: www.maps.googleapis.com. is not in the cert's altnames: DNS:*.googleapis.com, DNS:*.clients6.google.com, DNS:*.cloudendpointsapis.com, DNS:cloudendpointsapis.com, DNS:googleapis.com"

我已确认变量地址已根据输入参数值正确设置。这是否表明由 uri 和 qs 连接构建的最终查询字符串是错误的?如果是,我如何检查和验证最终字符串是什么?

这里显示了我的函数:

var lookup = function(input) {
    var address = input[0].address + ", " + input[0].city + ", " + input[0].state + ", " + input[0].zip;
    var apiKey = '<mykey>';
    var options = {
        uri: 'https://www.maps.googleapis.com/maps/api/geocode/json?',
        method: 'POST',
        json: true,
        body: input,
        qs: {
            address: address,
            key: apiKey
        }
    }
    request(options, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var info = JSON.parse(body);
            console.log(info);
        } else {
            console.log(error);
        }
    });
};

【问题讨论】:

    标签: node.js rest google-maps express post


    【解决方案1】:

    在一大块垃圾“响应”中,某处有链接的最终字符串。

    但你总是可以手动输入钥匙

    https://www.maps.googleapis.com/maps/api/geocode/json?key=yourApiKey
    

    它是 key= 或 apikey= 检查 googleapi 文档

    【讨论】:

    • 谢谢,当我收到错误时,它不允许我进入响应对象。
    【解决方案2】:

    原来错误是由于错误地将www. 添加到 Google Maps API 的 url 造成的。正确的字符串是:https://maps.googleapis.com/maps/api/geocode/json?

    【讨论】:

      猜你喜欢
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      相关资源
      最近更新 更多