简体   繁体   English

第一次点击后,点击Google Map Marker将不会打开信息窗口

[英]Click on google map marker won't open the info window after first click

I have a google map which will open a dialog box on a double click on the map. 我有一个谷歌地图,双击该地图将打开一个对话框。 If the user click OK, then it will add a marker on the map. 如果用户单击“确定”,则它将在地图上添加一个标记。 This marker will open the info windows on the first click (good behavior). 该标记会在第一次单击时打开信息窗口(行为良好)。

Another part of the code will display markers with info windows directly when the page load, those markers wont open the info window on the first click (bad behavior). 代码的另一部分将在页面加载时直接显示带有信息窗口的标记,这些标记在第一次单击时不会打开信息窗口(不良行为)。 The pointer will change from the hand to a finger on the first click, then on the second click the window will open. 第一次单击时,指针将从手变为手指,然后第二次单击,窗口将打开。

The following display the stores at the loading time: 以下显示了加载时的商店:

//display the markers
for(var i = 0; i < stores.length; i++) {
  var pos = new google.maps.LatLng(stores[i][8], stores[i][9]);
  all_stores_markers.push( new google.maps.Marker({                       
                                     position: pos,
                                     map: map,
                                     title: stores[i][1],
                                     clickable: true
                         }));
   all_stores_markers[i].html = 'some content';
   google.maps.event.addListener(all_stores_markers[i], 'click', function () {
    // where I have added .html to the marker object.
                                            infowindow.setContent(this.html);
                                            infowindow.open(map, this);  
                                            console.log("click marker");
                                    });                                  
}

This part is when the user is click OK in the dialog box after a double click on the map. 这是在双击地图后在对话框中单击“确定”的情况。 The following would make the marker clickable from the first click: 以下将使标记从第一次单击就可单击:

all_stores_markers.push( new google.maps.Marker({                       
                                position: location,
                                map: map,
                                clickable: true
                        }));
all_stores_markers[all_stores_markers.length-1].html = 'some content';
                        google.maps.event.addListener(all_stores_markers[all_stores_markers.length-1], 'click', function() {
                                infowindow.setContent(this.html);
                                infowindow.open(map, this);  
                        });

Here is the content of stores : 这是商店的内容:

 array(2) { [0]=> array(12) { [0]=> string(1) "1" [1]=> string(8) "aaaaaaaa" [2]=> string(15) "fjefjdoiajfdhai" [3]=> string(13) "jadoidjasoijd" [4]=> string(4) "7575" [5]=> string(10) "City folle" [6]=> string(9) "Australia" [7]=> string(13) "http://go.com" [8]=> string(8) "-20.0559" [9]=> string(7) "135.967" [10]=> string(10) "1818181818" [11]=> string(10) "1818181818" } [1]=> array(12) { [0]=> string(1) "2" [1]=> string(8) "New Shop" [2]=> string(11) "adjakdjakld" [3]=> string(6) "eqwewq" [4]=> string(4) "4343" [5]=> string(4) "Arff" [6]=> string(9) "Australia" [7]=> string(15) "http://test.com" [8]=> string(8) "-28.9985" [9]=> string(6) "123.75" [10]=> string(8) "92129181" [11]=> string(8) "82828282" } } 

I can't see much difference between both part of the code. 我看不到代码的两个部分之间的太大差异。 Any idea? 任何想法?

Sorry to ask this question, but I found the solution. 很抱歉提出这个问题,但我找到了解决方案。

For some very very strange reason, the difference of code was around the "title" attribute of the marker. 由于某些非常奇怪的原因,代码的区别在于标记的“ title”属性。 I removed it and everything is fine now. 我删除了它,现在一切都很好。

I can't explain why this would have an impact on the click... 我无法解释为什么这会对点击产生影响...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM