object - How to rid repeating lines in Javascript? -


i have javascript file adds markers custom google map, , code have:

var locations = [     // bloor station     new google.maps.marker({       position: new google.maps.latlng(43.670231, -79.386821),       url: "http://www.youtube.com/watch?v=nx7qnwegcni",       map: map,       icon: image     }),     // castle frank bridge     new google.maps.marker({       position: new google.maps.latlng(43.674759, -79.366643),       url: "http://www.youtube.com/watch?v=nx7qnwegcni",       map: map,       icon: image     }), // simeon park new google.maps.marker({   position: new google.maps.latlng(43.792333395471275, -79.38898265361786),   url: "http://www.youtube.com/watch?v=nx7qnwegcni",   map: map,   icon: image }), 

and continues each location have.

the problem have i'm using same map , image each marker; moreover, there other variables i'd add locations, without having write same line each marker; locations increases, repeating lines increase, , pain.

summarized, question is: how make can rid of these repeating lines?

i've tried run for-loop initialize each 1 after declaring url , position of each, doesn't work.

you can create helper function creates new marker object, assign values , push locations array.

example:

var locations = [];  function addmarker(lat, long, url) {    var marker = new google.maps.marker({     position: new google.maps.latlng(lat, long),     url: url,     map: map,     icon: image   });    locations.push(marker);  } 

and call addmarker add new marker

addmarker(43.792333395471275, -79.38898265361786, "url"); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -