0

I have yandex map on page. For this map i bind event handler 'actionend'.

I need in this handler get current coordinates of map center. Please help me make it.

live demo here.

Code:

ymaps.ready(init);

var myMap;

function init(){     
    myMap = new ymaps.Map("map", {
        center: [55.76, 37.64],
        controls: [],
        zoom: 18
    });   

    myMap.events.add('actionend', function (e) {
        console.log('stop action');
        console.log('print current coords of map center???????????????');
    });
};
ptortyr45
  • 147
  • 1
  • 11

1 Answers1

1

You can get the center coord by calling the getCenter() method, like this:

ymaps.ready(init);

var myMap;

function init(){     
    myMap = new ymaps.Map("map", {
        center: [55.76, 37.64],
        controls: [],
        zoom: 18
    });   

    myMap.events.add('actionend', function (e) {
       console.log(e.originalEvent.map.getCenter())
    });
};

See this doc.

Yonggoo Noh
  • 1,811
  • 3
  • 22
  • 37