javascript – Move label Yandex.Maps 2.1

Question:

Greetings. There is a great example of changing coordinates.

How to supplement it so that the marker (mark) appears on the first click, and when you click to another place on the map, it is rearranged?

I ask in advance in detail, tk. newbie.

Answer:

For example like this:

 ymaps.ready(init); var myMap, myPlacemark; function init() { myMap = new ymaps.Map('map', { center: [57.5262, 38.3061], // Углич zoom: 13 }); myPlacemark = new ymaps.Placemark(); myMap.events.add('click', function(e) { myPlacemark.geometry.setCoordinates(e.get('coords')); // устанавливаем метке координаты, высчитанные из положения клика myMap.geoObjects.add(myPlacemark); // ставим метку на карту }); }
 html, body, #map { width: 100%; height: 100%; padding: 0; margin: 0; }
 <script src="//api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <div id="map"></div>
Scroll to Top