Search code examples
javascriptyandex-maps

how to get the marker coordinates from geoObjectCollection Yandex.Map


There is a collection of objects displayed on the map. There is an event on the click of the label. How to determine the coordinates of the label that was clicked? .get('coords) will not work, you need to get exactly the coordinates prescribed in the collection, but how can I not understand, I tried .getCoordinates(), but I did not understand how to prescribe correctly, or do something else here...

var myGeoObject = new ymaps.GeoObjectCollection(
   {
    preset: 'islands#blueIcon'
});
for (var i = 0; i < coords.length; i++) {
    myGeoObject.add(new ymaps.Placemark(coords[i]));
}
myMap.geoObjects.add(myGeoObject);

myGeoObject.events.add('click', function (e) {
        
});

Solution

  • myGeoObject.events.add('click', function (e) {
            var click_coord = e.get('target').geometry.getCoordinates();
    });