here is my html code for creating a marker and infowindow (with ruby ββon rails)
var marker=[] function initMap() { var latLng1 = new google.maps.LatLng(1.352083, 103.819836); var myOptions = { zoom: 12, center: latLng1, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); for(i=0;i<gon.astatic.length;i++){ var latLng = new google.maps.LatLng(gon.astatic[i][1], gon.astatic[i][2]); if(i<2){ marker[i] = new MarkerWithLabel({position: latLng, map: map,icon:"/assets/green_MarkerV.png" ,labelClass: "labels",labelContent: gon.astatic[i][3]});} else { marker[i] = new MarkerWithLabel({position: latLng, map: map,icon:"/assets/green_MarkerN.png" ,labelClass: "labels",labelContent: gon.astatic[i][3]}); } var iw =new google.maps.InfoWindow({content: 'HI' }); google.maps.event.addListener(marker[i],"mouseover",function(e){iw.open(map,marker[i]);}) }
this gon is just some kind of "stupid" method that I use to transfer data from ruby ββon the rails controller to javascript.
for all markers, all windows are displayed in the corner. But for my other map (which has only one marker with infowindow) it works fine.
What could be my problem? Why is this information displayed in the wrong position? Instead of just above the marker?
EDIT:
After the problem is half a day, I feel that the problem is google.maps.event.addListener(marker[i],"mouseover",function(e){iw.open(map,marker[i]);})
when the listener calls the callback, the value inside the marker is i, which is not an actual number, so the marker is displayed on the corner. I feel that the problem cannot pass the variable to addListener, you can only enter the actual number. How to solve this?
user4029730
source share