-1

我正在尝试使用 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>

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

4

1 回答 1

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 中正确填充的吗?

于 2012-05-30T14:26:23.070 回答