Answer the question
In order to leave comments, you need to log in
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();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question