【问题标题】:google api place search not working node jsgoogle api地点搜索不起作用节点js
【发布时间】:2017-03-12 16:18:53
【问题描述】:

我正在尝试让 google maps api 工作。我找到了一个 npm 模块,可以很容易地将其连接到节点。

https://www.npmjs.com/package/googleplaces

我下载了模块并在 config.js 文件中添加了 api 密钥,就像它说的那样。 然后在我的 main.js 文件中,它基本上是服务器。我愿意

const googleplaces = require("googleplaces");
parameters = {
        location: [60.164315, 24.936667],
        types: "restaurant"
      };
googleplaces.placeSearch(parameters, function (error, response) {
    if (error) throw error;
    assert.notEqual(response.results.length, 0, "Place search must not return 0 results");
});

我收到以下错误: TypeError: googleplaces.placeSearch is not a function

我检查了节点模块,但无法找出问题所在。

【问题讨论】:

    标签: javascript node.js google-maps google-places-api


    【解决方案1】:

    基于this example here,您必须从您需要的 googleplaces 模块创建一个新对象。您只是直接调用它,这就是该方法不存在的原因;它只能在使用来自config.js 的配置设置实例化的对象上调用。

    替换这个:

    const googlePlaces = require('googleplaces');
    

    ...用这个:

    const config = require('./config.js');
    const GooglePlaces = require('googleplaces');
    const googlePlaces = new GooglePlaces(config.apiKey, config.outputFormat);
    

    【讨论】:

    • 但是 ./config.js 中没有配置,它在 nodel 模型 lib/test/config.js 中
    • 好的,然后要求lib/test/config.js。我不知道你的配置文件的位置哈,我相信你可以填写空格。
    猜你喜欢
    • 2012-12-31
    • 2018-06-14
    • 1970-01-01
    • 2017-09-16
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    相关资源
    最近更新 更多