I am using this code to draw points on the map:

marker = L.marker(coordsArray, {
    icon: myIcon,
    clickable: true,
    draggable: 'false',
    title: layerStringToJson.properties.id
}).bindPopup(coordinates).addTo(map).on('click', onClick);

And I have this method to get individual marker properties:

function onClick(e) {

But when I click on the markers, I always have the same result, always the same coordinates instead of the coordinates of every single marker.

Anyway the pop up shows the correct coordinates.

How can I get the individual properties of each marker?


2 options, for a single marker:

var lat = 43;
var lng = -76;

 var marker = L.marker([lat,lng]).bindPopup(lat.toString()+", "+lng.toString()).addTo(map);

For multiple markers use a feature group:

var myMarkers = L.featureGroup();

    // create loop here to add each marker to the featuregroup
    var marker = L.marker([lat,lng]).bindPopup(lat.toString()+", "+lng.toString()).addTo(map);
    //add the marker to the featuregroup
    //end loop


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.