【问题标题】:Cannot read property 'entries' of undefined in http://maps.googleapis.com/maps/api/无法读取 http://maps.googleapis.com/maps/api/ 中未定义的属性“条目”
【发布时间】:2017-09-13 19:40:57
【问题描述】:

一切正常,突然有一个错误Cannot read property 'entries' of undefined 可能是? (包括 googlemaps api)

Uncaught TypeError: Cannot read property 'entries' of undefined at js?key=<API_KEY>&callback=Map.init:105

Map.init

    Map.init = function (id) {
    id = id || 'map';
    map = new google.maps.Map(document.getElementById(id), {
        center: {lat: 46.409998, lng: 30.710000},
        scrollwheel: true,
        zoom: this.address ? 20 : 12
    });

    infoWindow = new google.maps.InfoWindow();

    map.addListener('zoom_changed', function () {
        var zoom = map.getZoom();
        if (zoom > zoomShowPoints && !pointsVisibility) {
            pointsVisibility = true;
            points.forEach(function (item) {
                item.setVisible(pointsVisibility);
            });
        } else if (zoom <= zoomShowPoints && pointsVisibility) {
            pointsVisibility = false;
            points.forEach(function (item) {
                item.setVisible(pointsVisibility);
            });
        }
    });

    getUsers();
};

【问题讨论】:

  • 浏览这个link。以便您了解如何创建最小、完整且可验证的示例
  • 需要添加与问题相关的代码。错误是您试图从对象或其他东西中读取属性entries,但是在您共享的代码中的任何地方都没有引用entries。我建议您阅读How to Askminimal reproducible example
  • 我知道他为什么不添加代码:这个错误发生在maps.googleapis.com/maps/api/js端点;所以这似乎是谷歌地图的问题。它现在就发生在我身上。
  • 问题出现在我使用的变量的名称中。变量的名称是“var Map”,所以我更改了名称,错误消失了

标签: javascript google-maps


【解决方案1】:

Google 于 2017 年 11 月更改了他们的 Maps API 脚本。他们开始使用全局变量 Map,这破坏了我们的网站。在我们的脚本中将 Map 变量重命名为 OurMap 解决了这个问题。

var Map;

更改为;

var OurMap;

【讨论】:

    【解决方案2】:

    通过添加版本参数解决了

    https://maps.googleapis.com/maps/api/js?v=3&key=&callback=Map.init

    【讨论】:

    • 不再工作了。确保您不使用谷歌地图使用的全局变量。就我而言,它是“地图”变量
    猜你喜欢
    • 2022-06-18
    • 1970-01-01
    • 2021-12-05
    • 2019-05-16
    • 2022-08-13
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    相关资源
    最近更新 更多