D
D
DeniSidorenko2019-02-22 11:07:26
JavaScript
DeniSidorenko, 2019-02-22 11:07:26

How to switch addresses for Yandex maps?

Recently I saw such functionality on one site.
Such a structure

<div class="items">
  <div class="item" data-lat='xxxx' data-ling='yyyy'>Адресс №1</div>
  <div class="item" data-lat='xxxx' data-ling='yyyy'>Адресс №2</div>
  <div class="item" data-lat='xxxx' data-ling='yyyy'>Адресс №3</div>
</div>

And a map from Yandex.
How can I make it so that when you click on the address, the center of the map moves?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-02-22
@DeniSidorenko

document.querySelector('.items').addEventListener('click', function(e) {
  const t = e.target;
  if (t.classList.contains('item')) {
    map.setCenter([ t.dataset.lat, t.dataset.lng ]);
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question