E
E
exdude2020-03-03 15:14:52
JavaScript
exdude, 2020-03-03 15:14:52

How to resolve the setCenter conflict in Yandex?

Good afternoon!
The error is as follows.
When creating a map, I use this code (automatic detection of the city on the map):

function init() {
var geolocation = ymaps.geolocation,
        myMap = new ymaps.Map('map', {
            center: [55, 34],
            zoom: 10
        }, {
            searchControlProvider: 'yandex#search'
        });
    geolocation.get({
        provider: 'yandex',
        mapStateAutoApply: true
    }).then(function (result) {
        result.geoObjects.options.set('preset', 'islands#redCircleIcon');
        result.geoObjects.get(0).properties.set({
            balloonContentBody: 'Мое местоположение'
        });
        myMap.geoObjects.add(result.geoObjects);
    });

    geolocation.get({
        provider: 'browser',
        mapStateAutoApply: true
    }).then(function (result) {
        result.geoObjects.options.set('preset', 'islands#blueCircleIcon');
        myMap.geoObjects.add(result.geoObjects);
    });


I create a button on the page and give it the following function:
function ChangeMap () {
    myMap.setCenter([58.010450, 56.229434]);
}


"setCenter" property. does not find( How to fix it? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Cheremkhin, 2020-03-03
@exdude

At first glance, the code is ok, it should work

And the center of the map does not find

what is happening (or not happening) describe more precisely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question