Z
Z
zixxx2019-11-07 19:02:27
2GIS
zixxx, 2019-11-07 19:02:27

How to get the coordinates of the selected marker?

Add markers like this

DG.marker([55.03606, 82.91325], {icon: myIcon}).addTo(map).bindPopup('55.03606, 82.91325');
DG.marker([55.03262, 82.91059], {icon: myIcon}).addTo(map).bindPopup('55.03262, 82.91059');
DG.marker([55.03114, 82.90941], {icon: myIcon}).addTo(map).bindPopup('55.03114, 82.90941');


How to correctly write a function so that when you click on a marker, you can get coordinates in it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-11-07
@zixxx

[
  [ 55.03606, 82.91325 ],
  [ 55.03262, 82.91059 ],
  [ 55.03114, 82.90941 ],
].forEach(n => {
  DG.marker(n, { icon: myIcon })
    .addTo(map)
    .bindPopup(n.join(', '))
    .on('click', onMarkerClick);
});

function onMarkerClick(e) {
  console.log(e.target.getLatLng());
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question