javascript - Gmaps Api 3 set individual icons for markers in an array -


below code, i'd have 3rd setting (link, coordinates, icon) if possible , add loop. each university should have unique icon.

see array below.

var markers = [     ['<a href="http://www.ship.edu">shippensburg university</a>', 40.06090, -77.52148],     ['<a href="http://www.millersville.edu">millersville university</a>', 39.99680, -76.35440],     ['kutztown university', 40.50980, -75.78410], ];   function initialize() {     var latlng = new google.maps.latlng(40.9, -77.5);     var myoptions = {         zoom: 7,         center: latlng,         maptypeid: google.maps.maptypeid.terrain,         maptypecontrol: false     };     var map = new google.maps.map(document.getelementbyid("gmap"),myoptions);     var infowindow = new google.maps.infowindow(), marker, i;     (i = 0; < markers.length; i++) {           marker = new google.maps.marker({             position: new google.maps.latlng(markers[i][1], markers[i][2]),             map: map,              icon: '../university.png'         });         google.maps.event.addlistener(marker, 'click', (function(marker, i) {             return function() {                 infowindow.setcontent(markers[i][0]);                 infowindow.open(map, marker);             }         })(marker, i));     } }  google.maps.event.adddomlistener(window, 'load', initialize); 

you add fourth item?

var markers = [     ['<a href="http://www.ship.edu">shippensburg university</a>', 40.06090, -77.52148, '../university.png'],     ... ]; 

and:

marker = new google.maps.marker({         position: new google.maps.latlng(markers[i][1], markers[i][2]),         map: map,         icon: markers[i][3]     }); 

although, i'd suggest giving properties names (rather dumping ton array) make code bit more readable:

var markers = [     {          link: '<a href="http://www.ship.edu">shippensburg university</a>',          lat: 40.06090, lng: -77.52148,          icon: '../university.png']     },     { ... } ]; 

and:

marker = new google.maps.marker({         position: new google.maps.latlng(markers[i].lat, markers[i].lng),         map: map,         icon: markers[i].icon     }); 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -