S
S
Stanislav2020-09-30 17:00:49
JavaScript
Stanislav, 2020-09-30 17:00:49

Yandex maps: why doesn't geoObjects.add work?

Please explain why the
this.myMap.geoObjects.add(result.geoObjects) method does not work?

class YandexMap{
    constructor(){
        this.myMap = new ymaps.Map('map', {
            center: [59.931, 30.370], 
            zoom: 12,
            controls: ['zoomControl']
        });
    }

    /**
     * Определение местоположения пользователя
     */
    getUserLocation(){
        ymaps.geolocation.get({
            mapStateAutoApply: true,
        }).then(
            function(result) {
                // Получение местоположения пользователя.
                let userAddress = result.geoObjects.get(0).properties.get('text');
                let userCoodinates = result.geoObjects.get(0).geometry.getCoordinates();
                // Пропишем полученный адрес в балуне.
                result.geoObjects.get(0).properties.set({
                    balloonContentBody: 'Адрес: ' + userAddress +
                                        '<br/>Координаты:' + userCoodinates
                });
                this.myMap.geoObjects.add(result.geoObjects)
            },
            function(err) {
                console.log('Ошибка: ' + err)
            }
        );
    }
}

let yMap = new YandexMap();
yMap.getUserLocation();

There are no errors in the console.
The data comes through result.geoObjects.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-09-30
@freeExec

Watch carefully where you get the result, and where you add it. Finally use a debugger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question