I have created a map containing a couple of markers and when the user clicks the markers it will open a popup page. It will just work fine when I had 5 markers but right now, I have to implement ~400 markers. So I would like to use a for loop for this. But somehow the markers won't appear on the map. It won't give any errors.
Here is my code:
let allMarkerOpts = [
{
finalLat: '35.6695585',
finalLng: '139.7611172',
iconUrl: 'hotelMarker.png',
locationName: 'openGinza();'
},
{
finalLat: '35.6961571',
finalLng: '139.7547658',
iconUrl: 'restaurantMarker.png',
locationName: 'openKanda();'
},
{
finalLat: '35.7058408',
finalLng: '139.7407026',
iconUrl: 'hotelMarker.png',
locationName: 'openDome();'
},
{
finalLat: '35.7012901',
finalLng: '139.7368178',
iconUrl: 'coffeehouseMarker.png',
locationName: 'openKagurazaka();'
},
];
for ( var i; i < 5; i++ ) {
(function(){
let markerOptions = {
map: map,
position: {
lat: allMarkerOpts[i].finalLat,
lng: allMarkerOpts[i].finalLng
}
};
markerOptions.icon = {
url: "https://sitename.com/demo/img/destinations/markers/" + allMarkerOpts[i].iconUrl,
scaledSize: new google.maps.Size(
52,
57),
size: new google.maps.Size(
52,
57),
anchor: new google.maps.Point(
26,
57)
};
let marker = new google.maps.Marker(markerOptions);
google.maps.event.addListener(marker, 'click', (function(marker) {
return function() {
allMarkerOpts[i].locationName
}
})(marker));
})();
};
