我正在尝试将现有的工作 Google map 代码迁移到基于 Javascript 对象的方式,但我遇到了一些错误,无法弄清楚。最初,所有标记都已加载,并且在任何事件(单击、拖动等)上)它抛出错误 TypeError: g.j is undefined。
我猜下面几行是错误的原因:
google.maps.event.addListener(mapObj.polymap, "dragend", mapObj.mapSearch());
google.maps.event.addListener(mapObj.polymap.getPath(), "insert_at", mapObj.mapSearch());
google.maps.event.addListener(mapObj.polymap.getPath(), "remove_at", mapObj.mapSearch());
google.maps.event.addListener(mapObj.polymap.getPath(), "set_at", mapObj.mapSearch());
最佳答案
google.maps.event.addListener
的第三个参数应该是一个函数,但您提供的是函数调用,而不是函数。
您必须删除函数名称后面的括号:
google.maps.event.addListener(mapObj.polymap, "dragend", mapObj.mapSearch);
google.maps.event.addListener(mapObj.polymap.getPath(), "insert_at", mapObj.mapSearch);
google.maps.event.addListener(mapObj.polymap.getPath(), "remove_at", mapObj.mapSearch);
google.maps.event.addListener(mapObj.polymap.getPath(), "set_at", mapObj.mapSearch);
//.................
google.maps.event.addDomListener(window, 'load', mapObj.init);
关于javascript - 将其迁移到 Javascript OOP 时出现 TypeError : g. j 未定义(Google map ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765699/