JavaScript Mapbox多个标记addlayer错误

时间:2018-06-21 17:15:14

标签: javascript mapbox marker

当我尝试向地图添加多个标记时遇到问题

for (var i = 0; i < keys.length; i++) {
            var k = keys[i];
            var latitude = dados[k].latitude;
            var longitude = dados[k].longitude;
            var email = dados[k].email;
            var bateria = dados[k].bateria;

            var example = new L.latLng({lat: latitude, lng: longitude});
            console.log(example);
           // var marker = new L.marker(example).addTo(mapGeo);
            var marker = new L.marker().setLngLat(example).addTo(mapGeo);
}

我正在从数据库中接收到我的纬度和经度,并且在出现此错误时

Uncaught TypeError: Cannot read property 'addLayer' of undefined
at e.addTo (leaflet-src.js:3902)
at gotData (MAP.html:135)
at EventRegistration.js:65
at Object.t.exceptionGuard (util.js:536)
at e.raise (EventQueue.js:158)
at e.li (EventQueue.js:111)
at e.raiseEventsForChangedPath (EventQueue.js:95)
at e.ee (Repo.js:200)
at t.Ot (PersistentConnection.js:449)
at t.wt (PersistentConnection.js:443)

我也尝试了var marker = new L.marker().setLngLat(example).addTo(mapGeo);,但没有成功,并给了我这个错误

util.js:547 Uncaught TypeError: (intermediate value).setLngLat is not a function
at gotData (MAP.html:136)
at EventRegistration.js:65
at Object.t.exceptionGuard (util.js:536)
at e.raise (EventQueue.js:158)
at e.li (EventQueue.js:111)
at e.raiseEventsForChangedPath (EventQueue.js:95)
at e.ee (Repo.js:200)
at t.Ot (PersistentConnection.js:449)
at t.wt (PersistentConnection.js:443)
at e.wt (Connection.js:262)

欢迎任何帮助!

0 个答案:

没有答案