2011-11-09 33 views
0

次のコードを使用して、いくつかのマーカーをGoogleマップにプッシュしようとしています。しかし、それは動作していないようです。地図は正しい位置に集中していますが、私はマーカーを見ることができます。Google maps API multiple marker

var points = [<asp:literal runat="server" id="litPoints"/>]; 

    $(document).ready(function() { 
     var mapCenter = new google.maps.LatLng(<asp:literal runat="server" id="litMapCentre"/>); 
      var options = { 
       zoom:<asp:literal runat="server" id="litZoomLevel"/>, 
       center: mapCenter, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 


     var map = new google.maps.Map($("#monitorMap")[0], options);   
     GetMap(map, points); 
    }); 






    function GetMap(map, mappoints) {  

     var image=new google.maps.MarkerImage('../Images/map/iconr.png', 
        new google.maps.Size(20,32), 
        new google.maps.Point(0,0)); 

     for(var i=1; i < points.length; i++) { 
      var m=points[i]; 

      var mylatlng=new google.maps.LatLng(m[0], m[1]); 
      var marker=new google.maps.Marker({ 
       position: mylatlng, 
       map: map, 
       icon: image}); 
     }  
} 
+0

最近の質問を受け入れてください! – hsz

答えて

0

チェンジ第二の機能は、このようなものにする:あなたはmappointsという変数を作成したが、その後のポイントとしてそれを参照して

function GetMap(map, mappoints) {  

     var image=new google.maps.MarkerImage('../Images/map/iconr.png', 
        new google.maps.Size(20,32), 
        new google.maps.Point(0,0)); 

     for(var i=0; i < mappoints.length; i++) { 
      var m=mappoints[i]; 

      var mylatlng=new google.maps.LatLng(m[0], m[1]); 
      var marker=new google.maps.Marker({ 
       position: mylatlng, 
       map: map, 
       icon: image}); 
     } 

。また、javascript配列はゼロインデックスされているので、それらをループすると、通常は0ではなく1から始める必要があります。