D
D
denism3002019-12-24 17:40:11
JavaScript
denism300, 2019-12-24 17:40:11

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

1 answer(s)
0
0xD34F, 2019-12-24
@denism300

Open the documentation and see what the setCoordinates method should accept.
Then see what you send him.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question