我在地图上的群集无效

时间:2012-05-30 10:31:36

标签: javascript google-maps-api-3 markerclusterer

我正在尝试使用JS和VB.NET中的Google Maps API v3制作地图,作为地图的服务器端数据数组。我的地图成功加载了群集,但是当我尝试在地图上应用群集时,我的标记变得不可见而不会在地图上显示。
这是我制作地图和群集的代码

<script src="http://www.google.com/jsapi"></script>

    <script type="text/javascript">
      var script = '<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer';
      if (document.location.search.indexOf('compiled') !== -1) {
        script += '_compiled';
      }
      script += '.js"><' + '/script>';
      document.write(script);
    </script>  
 <script type="text/javascript">
  google.load('maps', '3', {
        other_params: 'sensor=false'
      });

      google.setOnLoadCallback(initialize);

 var map; 
 var markers = [];    
 var markerClusterer = null;
 function initialize() {
 var GPS = <%=GPS %>
 var map_center = new google.maps.LatLng(31.2330555556,72.3330555556);
     var myOptions = {
      zoom: 6,
      scaleControl:true,
      pancontrol: true,
      streetViewControl: true,
      center: map_center,
      mapTypeControl: true,
      mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
      mapTypeId: google.maps.MapTypeId.HYBRID
    }    
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var infowindow = new google.maps.InfoWindow();

    var image = 'ico/gn.png';
        for(var i=0; i<GPS.length; i++)
         {

         var marker=new google.maps.Marker({
         position:GPS[i].GPS,
         draggable:true,
         icon:image,
         Info: '<table frame=box><tr><td align="Left"><font face="Arial" size=2 color=#336699>Shop Name:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].SHOP + '</font></td></tr><tr>'+
          '<td align="Left"><font face="Arial" size=2 color=#336699>Owner:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].OWNER + '</font></td></tr>'+
          '<td align="Left"><font face="Arial" size=2 color=#336699>Mobile:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].MOBILE + '</font></td></tr>'+
          '<tr><td align="Left"><font face="Arial" size=2 color=#336699>Distributer:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].DIST + '</font></td></tr><tr>'+
          '<tr><td align="Left"><font face="Arial" size=2 color=#336699>Region:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].REGION + '</font></td></tr>'+
          '<tr><td align="Left"></td><td align="Left"><font face="Arial" size=2 color=#336699><a target=_blank href=http://221.120.216.52/elp/sfpl.php?ccode=01&amp;&regno='+ GPS[i].REGNO +'>View</a></td></tr>'+
          '</table>',
          title:GPS[i].SHOP + '(' +GPS[i].DIST + ' )'
         });
         markers.push(marker);
         google.maps.event.addListener(markers[i], 'click', function() {
            infowindow.setContent(this.Info);
            infowindow.open(map,this);
            }); 
         }
         markerClusterer = new MarkerClusterer(map,markers,
         {
         maxZoom:5
         });
         }



    </script>

任何?请帮助我摆脱这个问题,并告诉我我的代码中缺少什么。

1 个答案:

答案 0 :(得分:0)

我不确定你的问题是什么。当我更换

var GPS = <% GPS %>

使用:

var pos1 = new google.maps.LatLng(31.2330555556,72.3330555556);
var pos2 = new google.maps.LatLng(30.5,71.1);
var pos3 = new google.maps.LatLng(32.4,73.4);

  var test = {
    GPS: pos1,
    SHOP: 'Blah',
    OWNER: 'bob',
    REGION: 'pakistan',
    DIST: 1
 }

 var test2 = {
    GPS: pos2,
    SHOP: 'Blawefah',
    OWNER: 'cat',
    REGION: 'pakistan',
    DIST: 2
 }

 var test3 = {
    GPS: pos3,
    SHOP: 'Blsdfah',
    OWNER: 'fred',
    REGION: 'pakistan',
    DIST: 3
 }

 var GPS = new Array();
 GPS[0] = test;
 GPS[1] = test2;
 GPS[2] = test3;

我得到了三个测试标记。当我缩小时,这三个标记消失并出现标记簇,编号为3(表示簇中标记的数量)。

你确定你的GPS阵列是从VB正确填充的吗?