G
G
grabbee2021-08-14 17:04:15
Yandex maps
grabbee, 2021-08-14 17:04:15

How to get the coordinate when moving the map?

It seems that you need to use the actiontickcomplete event - there you can get event.get('tick') in which there will be a globalPixelCenter - but I need the coordinate just before the map stops moving
* Setting the marker to the center of the map as in Yandex.Taxi - so that the marker always remains in the center maps, even when the map is moving

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Developer, 2021-08-18
@samodum

there is an onMove event

R
Ruslan, 2021-09-04
@twiSk

I had the same task. Decided like this:

window.myMap = new ymaps.Map('map', {
    controls: [],
    center: coordinates,
    zoom: 11,
});

const centerPoint = new ymaps.Placemark(coordinates, {}, {
    preset: 'islands#whiteStretchyIcon',
});

myMap.events.add('actiontickcomplete', (event) => {
    const { globalPixelCenter, zoom } = event.get('tick');
    const projection = myMap.options.get('projection');
    const coords = projection.fromGlobalPixels(globalPixelCenter, zoom);

    centerPoint.geometry.setCoordinates(coords);
});

myMap.geoObjects.add(centerPoint);

https://jsfiddle.net/Eseath/ecrf5yd4/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question