【问题标题】:Cannot call method 'getPosition' of undefined无法调用未定义的方法“getPosition”
【发布时间】:2014-03-18 19:58:21
【问题描述】:

我在使用 Google Maps API 时遇到了问题。 Google 向我返回错误:未捕获的 TypeError:无法调用未定义的方法“getPosition”。在这段代码中:

function center_map(current) {
        var default_image_path = js_load_parameters.theme_default_path;
        map.setCenter(markers[current].getPosition());
        for(i = 0; i < quantity; i++) {
            markers[i].setIcon(default_image_path+'/layout/images/marker_map_1.png');
        }
        markers[current].setIcon(default_image_path+'/layout/images/marker_map_1_act.png');
        current_location = current;
    }

【问题讨论】:

  • 嗯,当然,这表明markers[current] 正在评估为未定义。现在,这是您的代码还是 API 库的一部分?
  • 电流值是多少?标记[当前] 是否存在?

标签: javascript api google-maps maps


【解决方案1】:

current 的值是多少?标记[当前] 是否已定义? (可能不是)
这里markers[current] 未定义。

currentmarkers 添加控制台日志并查看打印的值是什么。

确保您定义了标记和计数。

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 2020-07-27
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    相关资源
    最近更新 更多