I’m working in a project, in Meteor based on NodeJS, I need create “markers” (Places) on the map via Google Maps API.
These markers are in a “list” array
let list = Offers.find({});
list = [
{
place: "Teste2",
offer: "Teste Offer2",
loc: {
coordinates: [-50.1681836, -25.0869446]
}
},
{
place: "Teste1",
offer: "Teste Offer1",
loc: {
coordinates: [-40.1681836, -20.0869446]
}
}];
And these respective locations must be displayed on the map, each location with its respective marker…
let count = 0;
list.forEach(function(offer) {
console.log(offer);
// Animation Timeout
setTimeout(function() {
// Add the marker on the map
let marker = new google.maps.Marker({
position: {lat: offer.loc.coordinates[1], lng: offer.loc.coordinates[0]},
map: map.instance,
animation: google.maps.Animation.DROP
});
// Create the string into the infowindow
let contentString = '<p><strong>' + offer.place + '</strong></p>' +
'<p>' + offer.offer + '</p>';
// Add the infowindow for each marker
marker.addListener('click', function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
}, count * 200);
count++;
});
However, just shown is only the first array position (“Teste2”), not all multiple values by “list”.