Answer the question
In order to leave comments, you need to log in
Why do the label coordinates not change?
I sketched a small script that, on click on the map, should put a mark at the click point.
However, the label does not change its location, although I get the coordinates when I click.
ymaps.ready(function() {
var myMap = new ymaps.Map('YMapsID', {
center: [55.751574, 37.573856],
zoom: 9
}, {
searchControlProvider: 'yandex#search'
});
myGeoObject = new ymaps.GeoObject({
geometry: {
type: "Point",
coordinates: [55.751574, 37.573856]
},
properties: {
balloonContent: 'Привет!'
}
}, {
preset: 'twirl#redStretchyIcon',
draggable: true
});
myMap.geoObjects.add(myGeoObject);
myMap.events.add('click', function (e) {
var clk_coords = e.get('coords');
myGeoObject.geometry.setCoordinates([clk_coords[0] + ', ' + clk_coords[1]]);
document.getElementById('geomapx').value = clk_coords[0];
document.getElementById('geomapy').value = clk_coords[1];
});
myGeoObject.events.add("dragend", function(e) {
var coords = e.get('target').geometry.getCoordinates();
document.getElementById('geomapx').value = coords[0];
document.getElementById('geomapy').value = coords[1];
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question