'leaflet.js:5 Uncaught TypeError: Cannot read properties of undefined (reading 'trim')
I've created a map with Leaflet and jQuery and I wanted to add Clustergroups to my Markers but I am getting the error : leaflet.js:5 Uncaught TypeError: Cannot read properties of undefined (reading 'trim')
Here my code:
$.get(url).done(function (data) {
var markers = L.markerClusterGroup();
for (let i = 0; i < data.length; i++) {
var title = "hi";
let marker = L.marker(([data[i].latitude, data[i].longitude]));
marker.bindPopup(title);
markers.addLayer(marker);
}
mymap.addLayer(markers);
}
I tried to search for the problem and found this https://github.com/Leaflet/Leaflet.markercluster/issues/724 but the problem was never answered. Also i read about different types of problems that it is maybe the problem of jQuery that it cannot define the variables. But I dont't know where my mistake could be, can anyone see it? Thanks in advance
Solution 1:[1]
You are useing twice () in marker creation.
Change:
let marker = L.marker(([data[i].latitude, data[i].longitude]));
to:
let marker = L.marker([data[i].latitude, data[i].longitude]);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Falke Design |
