2016-04-06 22 views
0

Bir tıklama ile etkinleştirilen birden fazla işaretçi ve infowindows eklemek istiyorum. Bir işaret tıklattıktan sonra, tüm işaretçiler için aynı açıklığı açtıktan sonra, işaretçinin ilgili ayrıntılarını sunmakta zorlanıyorum. bilgi döngü bunun için geliyorGömülü çoklu işaretleyiciler

function GetMarkerSuccess(results) { 
     results = $.parseJSON(results.d); 
     markers = []; 
     infowindows = []; 

     for (var i = 0; i < results.length; i++) { 
      var myLatLng = { lat: results[i].Latitude, lng: results[i].Longitude }; 

      var marker = new google.maps.Marker({ 
       position: myLatLng, 
       map: map, 
       icon:'images/car.png' 
      }); 
      var infowindow = new google.maps.InfoWindow({ 
      content: "<div style='text-align:right'><h3>" + results[i].Date.substring(0, 10) + "</h3><p> התחלה: " + results[i].Starttime + " סיום: " + results[i].Endtime + "</p><p> &#8362 מחיר:" + results[i].Price + "</p></div>" 
      }); 
      markers.push(marker); 
      infowindows.push(infowindow); 
      listenMarker(marker); 
      function listenMarker(marker) { 

       google.maps.event.addListener(marker, 'click', function() { 
        infowindow.open(map, marker); 
       }); 
      } 

     } 
    } 
+0

[Infowindows ile Google Maps API Çoklu Markerlerinin] Olası yinelenen (http://stackoverflow.com/questions/11106671/ kodudur google-haritalar-api-çoklu-işaretleri-ile-infowindows) –

+0

onları benzersiz –

cevap

0
 function GetMarkerSuccess(results) { 
      results = $.parseJSON(results.d); 
      markers = []; 
      infowindows = []; 

      for (var i = 0; i < results.length; i++) { 
       var myLatLng = { lat: results[i].Latitude, lng: results[i].Longitude }; 

       var marker = new google.maps.Marker({ 
        position: myLatLng, 
        map: map, 
        icon:'images/car.png' 
       }); 
       var infowindow = new google.maps.InfoWindow({ 
       content: "<div style='text-align:right'><h3>" + results[i].Date.substring(0, 10) + "</h3><p> התחלה: " + results[i].Starttime + " סיום: " + results[i].Endtime + "</p><p> &#8362 מחיר:" + results[i].Price + "</p></div>" 
       }); 
       markers.push(marker); 
       infowindows.push(infowindow); 
       listenMarker(marker); 
       function listenMarker(marker) { 
       google.maps.event.addListener(marker,'click',  (function(marker,content,infowindow){ 
        return function() { 
        infowindow.setContent(content); 
        infowindow.open(map,marker); 
       }; 
       })(marker,content,infowindow)); 
       } 
      } 
     } 
+0

, hala aynı yapmak zorunda değilsiniz –