简体   繁体   English

谷歌地图:google.maps.event.addListener

[英]Google Maps : google.maps.event.addListener

i have shapes and i draw it in maps : 我有形状,并在地图上绘制:

    shapes; //array of shapes, i draw it from string that i take from db

    for (var i = shapes.length - 1; i >= 0; i--) {
        google.maps.event.addListener(shapes[i], 'click', function() {
            myFunc(shapes[i]); //function to edit shapes[i]
        });
    };

when i do this : 1. eg i have shapes length = 5; 当我这样做时:1.例如,我的形状长度= 5; 2. i click in 1 of the shape but myFunc always called with i=5 so myFunc always call shapes[5] 2.我单击形状的1,但myFunc总是以i = 5调用,因此myFunc总是调用shape [5]

i already try : Passing a pointer to objects method safely to google.maps.event.addListener 我已经尝试过: 将指向对象方法的指针安全地传递给google.maps.event.addListener

but still fail, can someone give me advice? 但仍然失败,有人可以给我建议吗?

shapes; 形状; //array of shapes, i draw it from string that i take from db //形状数组,我是从数据库中提取的字符串绘制的

for (var i = shapes.length - 1; i >= 0; i--) {
 (function (i) {
    google.maps.event.addListener(shapes[i], 'click', function() {
        myFunc(shapes[i]); //function to edit shapes[i]
    });
 })(i);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 google.maps.event.addListener 不是函数 - google.maps.event.addListener is not a function google.maps.event.addListener和Fall调用 - google.maps.event.addListener and fall calls 如何在google.maps.event.addListener中使用它 - How to use this in google.maps.event.addListener 在google.maps.event.addlistener(自动完成,...)中注册“点击”事件? - Registering a 'click' event with google.maps.event.addlistener(autocomplete, …)? google.maps.event.addListener for tileloaded 突然不触发 - google.maps.event.addListener for tilesloaded suddenly not firing 将指向对象的方法安全地传递给google.maps.event.addListener - Passing a pointer to objects method safely to google.maps.event.addListener 使用命名函数在循环中添加google.maps.event.addListener - Adding google.maps.event.addListener in a loop with named function 仅在google.maps.event.addListener()中显示街道地址 - show just the street address in google.maps.event.addListener() Asp和Google Map Api:通过google.maps.event.addListener显示asp:textbox的位置 - Asp & Google Map Api: Show location to asp:textbox through google.maps.event.addListener 我是否必须使用google.maps.event.addListener(marker,'click',function(){})? - Do I have to use google.maps.event.addListener(marker, 'click', function(){})?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM