查看地图上的多个标记
我试图查看地图上的多个标记,所以我这样做了,但不幸的是没有工作,有人会告诉我错误在哪里吗?我正在使用 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在循环 add.locations 中的所有内容...
如果你想遍历studentAddresses forEach 循环应该是这样的
You are looping over whatever is in add.locations…
If you want to loop over studentAddresses the forEach loop should look like this