marker.setDraggable(false) 在 API Google 地图的 main.js 中引发异常

发布于 2025-01-08 03:54:13 字数 397 浏览 1 评论 0原文

我在 JavaScript 中有这段代码:

google.maps.event.addListener(mark, 'dragend',x(mark));

function x(mark)
{
    mark.setDraggable(false);
}

当我将标记移动到另一个位置时,它会在 main.js 中抛出此异常:

SCRIPT5007:Can not get value of property 'apply': the object is null or undefined     
main.js, Línea 23 Carácter 104

它只发生在 IE 中,在 Chrome 和 Firefox 中,代码运行完美。

I have this code in JavaScript:

google.maps.event.addListener(mark, 'dragend',x(mark));

function x(mark)
{
    mark.setDraggable(false);
}

When I move a marker to another position it throws this exception in main.js:

SCRIPT5007:Can not get value of property 'apply': the object is null or undefined     
main.js, Línea 23 Carácter 104

It only happens in IE, in Chrome and Firefox the code runs perfectly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧 2025-01-15 03:54:13

尝试使用 google.maps.event.addListener(mark, 'dragend', x);

Try to use google.maps.event.addListener(mark, 'dragend', x);

做个少女永远怀春 2025-01-15 03:54:13

您可以将标记设为全局变量:

var mark;

function initialize() {
    mark = new google.maps.Marker() //Set up marker here
    google.maps.event.addListener(mark, 'dragend', doMarkStuff);
}

function doMarkStuff() {
    mark.setDraggable(false);
}

假设您在初始化函数中初始化地图和标记。

You could make the marker a global variable:

var mark;

function initialize() {
    mark = new google.maps.Marker() //Set up marker here
    google.maps.event.addListener(mark, 'dragend', doMarkStuff);
}

function doMarkStuff() {
    mark.setDraggable(false);
}

Assuming that you initialize your map and marker in the initialize function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文