javascript - Google map multiple marker -


i know has been asked lot of times on net. still cant solve this, been few days still can't solve it. still new google map api thing , maybe there have mixed or something.

below current code:

var places = [               ['car park', 1.301526,103.849379, 4],               ['bus stop', 1.301132,103.850077, 3],               ['mrt', 1.298515,103.845785, 2],               ['success human resource center', 1.301486,103.849712, 1]             ];              var companyimage0 = new google.maps.markerimage('images/map-icon.png',                 new google.maps.size(54,62),                 new google.maps.point(0,0),                 new google.maps.point(50,50)             );              var companyimage1 = new google.maps.markerimage('images/mrt.png',                 new google.maps.size(30,30),                 new google.maps.point(0,0),                 new google.maps.point(50,50)             );              var companyimage2 = new google.maps.markerimage('images/bus-stop.png',                 new google.maps.size(30,33),                 new google.maps.point(0,0),                 new google.maps.point(50,50)             );              var companyimage3 = new google.maps.markerimage('images/car-park.png',                 new google.maps.size(30,30),                 new google.maps.point(0,0),                 new google.maps.point(50,50)             );              var companyshadow = new google.maps.markerimage('images/logo_shadow.png',                 new google.maps.size(54,62),                 new google.maps.point(0,0),                 new google.maps.point(65, 50)             );              /*var companypos = new google.maps.latlng(1.301486,103.849712);*/              (var = 0; < places.length; i++) {             var place = places[i];             var mylatlng = new google.maps.latlng(place[1],place[2]);             var marker = new google.maps.marker({                 position: mylatlng,                 map: map,                 shadow: companyshadow,                 icon: companyimage[i],                 title: 'singapore',                 zindex: places[2][2]});             } 

aside that, want display infowindow when user click on shrc marker, bus stop , mrt have nothing when marker clicked.

appreciate kind souls can me out on this. in advance.

i'm not quite sure you're trying here, since nothing error you're receiving. however, have 3 errors in code:

companymarker hasn't been initialized, , you're using wrong variable name , syntax z-index. remember arrays zero-based index,

places[2] // retrieve shrc row data places[2][2] //will retrive z-index number shrc row 

so, try following changes:

var places = [   ['bus stop', 1.301132,103.850077, 3],   ['mrt', 1.298515,103.845785, 2],   ['shrc', 1.301486,103.849712, 1] ];  //change marker companymarker var companymarker = new google.maps.marker({   position: mylatlng,   map: map,   shadow: companyshadow,   icon: companyimage,   title: 'singapore',   zindex: places[2][2]}); //<- change place[3], z-index number }  google.maps.event.addlistener(companymarker, 'click', function() {   infowindow.open(map,companymarker); }); 

lastly, if have other event handlers bus stop , mrt markers, need add infowindow.close(map, somemarkername) companymarker listener close respective windows.


Comments