I'm trying to view multiple markers on the map, so I did this but unfortunately didn't work, any one would tell me where the error is? I'm using JavaScript.
var studentAddresses = [
[37.1, -78.024],
[37.5, -78.044],
[37.9, -78.064]
];
add.locations.forEach((studentAddresses) => {
// add marker to map
var marker = new mapboxgl.Marker(el)
.setLngLat([studentAddresses[0][0], studentAddresses[0][1]])
.setPopup(popup)
.addTo(map);
You are looping over whatever is in add.locations… If you want to loop over studentAddresses the forEach loop should look like this
studentAddresses.forEach((address) => {
// add marker to map
var marker = new mapboxgl.Marker(el)
marker.setLngLat([address[0], address[1]])
.setPopup(popup)
.addTo(map);
}
)