View Single Post
Old 02-13-2013, 03:32 PM   PM User | #1
michael_cassio
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
michael_cassio is an unknown quantity at this point
infowindow GMaps no iteration over text

Hello, I wrote a GMaps JS Script which allows one to toggle different markers I fetch the data via php from a mySQL-Database:

In order to open so-called infowindows I use G-Maps Event-Listeners. In the following script everything works just fine: the toggle function works. It' possible to open an info-windows on each marker.
Howerver, I always get the the Infowindow-text of the last marker. So, there is no iteration over the text. I know that I always overwrite the content of the infowindow (until I have only the last item), so I dont' know how to fix it...
I would be very grateful for just a hint. Thank you!!

Code:
 var deutschland = new google.maps.LatLng(51,9);
  

     function initialize(){

      var mapOptions = { zoom: 6,
                         center: deutschland,
                         streetViewControl: true,
                         scaleControl: true,
                         mapTypeControl: true,
                         mapTypeId: google.maps.MapTypeId.ROADMAP };


   var map = new google.maps.Map(document.getElementById("map-container"),mapOptions);
  

   lat_data = [

['mid',50.0010400,9.0730700,'BluVisio','marker.png','infowindow text 1'],
['mid',50.2010057,8.2592738,'Alco GmbH','marker.png','infowindow text 2'],
['West',50.7430120,7.1264100,'Computer Wunsch Systems OHG','marker_green.png','infowindow 3 text'] ....

];



   markers = [];
   var i, newMarker;

   for (i = 0; i < lat_data.length; i++) {

       var shadow = new google.maps.MarkerImage('http://maps.google.com/mapfiles/shadow50.png',
       new google.maps.Size(37,32),
       new google.maps.Point(0,0),
       new google.maps.Point(0,32));

    var image = new google.maps.MarkerImage('http://maps.google.com/mapfiles/'+lat_data[i][4],
       new google.maps.Size(20,32),
       new google.maps.Point(0,0),
       new google.maps.Point(0,32));

     newMarker = new google.maps.Marker({
       position: new google.maps.LatLng(lat_data[i][1], lat_data[i][2]),
       map: map,
       title: lat_data[i][3],
       icon: image,
       shadow: shadow
     });

     newMarker.category = lat_data[i][0];
     newMarker.setVisible(true);

     var infowindow = new google.maps.InfoWindow({
           content: lat_data[i][5]
       });

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

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

     markers.push(newMarker);
   }

   }

    function displayMarkers(category) {
      var i;

     for (i = 0; i < markers.length; i++) {
       if (markers[i].category == category) {
         if (markers[i].getVisible()) {
              markers[i].setVisible(false); }

        else { markers[i].setVisible(true); } } }

   }
michael_cassio is offline   Reply With Quote