Google Maps MarkerClusterer无法使用或隐藏所有标记 [英] Google Maps MarkerClusterer either doesn't work or hides all markers

查看:89
本文介绍了Google Maps MarkerClusterer无法使用或隐藏所有标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...取决于我放行的位置

...depending on where I put the line

var mc = new markerclusterer(map);

如果它出现在示例似乎建议的位置 - 就在var map引入之后 - 所有标记消失(例如运行此处)。

If it goes where the examples seem to suggest - right after "var map" is introduced - all the markers disappear (example running here).

没有mc变量的版本在所有标记可见的情况下运行。

A version without the mc variable runs with all markers visible.

在google.maps.event之后引入mc变量时。 addListener函数如这里所示,似乎也取消了它的效果,显示标记。

When the mc variable is introduced after the google.maps.event.addListener function as shown here, it seems also to cancel its effect and markers are shown.

locations变量是一个数组,包含地理定位数据和格式化的HTML(在电子表格中生成),用于地图上的所有点,并传递给放置它们的标记。

The locations variable is an array containing geolocation data and ready-formatted HTML (produced in a spreadsheet) for all points on the map, which is passed to the markers to place them.

我认为问题可能是与数据库引用地理位置数据的markerclusterer一起使用时应该引用标记?我见过其他人使用变量markerarray,但我担心如果我搞乱它我将打破代码的html和地理位置提取部分。

I think the issue may be that to be used with the markerclusterer the array is referring to the geolocation data, when it should refer to markers? I've seen other people using a variable markerarray, but I'm worried if I mess with it I'll break the html and geolocation extraction part of the code.

任何人都可以帮助解释为什么var mc失败了吗?我已加载 http://标题中有google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js ,因此它应该可以工作,我在代码中看不到任何语法错误。

Can anyone help explain why var mc is failing? I've loaded http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js in the header, so it should work and I can't see any syntax errors in my code.

这是我用JS做的第一件事,它很棒,但我只是想用标记簇来完成它!非常感谢帮助。

This is the first thing I've made with JS and it's great but I just want to finish it off with the marker clusters now ! Help would be much appreciated.

编辑:我也试过玩这个,但就像我说这里的数组是我理解的两倍,所以我无法让它工作:

I also tried playing with this but like I say the array here is two-fold to my understanding, so I couldn't get it to work:

建议:

...
var infowindow = new google.maps.InfoWindow();

var marker, i;
map.markers = []; // ADD THIS LINE
for (i = 0; i < locations.length; i++) {  
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
    });
    map.markers.push(marker); // ADD THIS LINE
...

我的代码片段:

...
var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });
...


推荐答案

你有2个问题。


  1. 你永远不会将你的标记添加到 MarkerClusterer

var markers=[];
for (var i = 0; i < locations.length; i++) {
  var marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0]);
      infowindow.open(map, marker);
    }
  })(marker, i));
  markers.push(marker);
}
var mc = new MarkerClusterer(map, markers);


  • markerclusterer的大小写不正确(javascript区分大小写),它应该是MarkerClusterer。

  • markerclusterer has the incorrect case (javascript is case sensitive), it should be MarkerClusterer.

    工作示例

    这篇关于Google Maps MarkerClusterer无法使用或隐藏所有标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆