N
N
nastya_zholudeva2017-11-20 16:57:03
JavaScript
nastya_zholudeva, 2017-11-20 16:57:03

How to reload the Yandex map if the coordinates of the center have changed?

On the site you can choose different cities. When the user selects a city, then the coordinates of the center of this city are stored in localStorage, and then

centerArray = [JSON.parse(localStorage.getItem('town')).lat, JSON.parse(localStorage.getItem('town')).long];

 console.log('centerArray', centerArray);

      myMap = new ymaps.Map("map", {
           center: centerArray,
            zoom: 15,
       });


How to make the map reload when changing the city. I print out in console.log the coordinates of the center change, i.e. everything works, but the map does not update

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2017-11-20
@nastya_zholudeva

Create a map once and use the setCenter() method or some toPan() method to animate it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question