You must determine the coordinates of the location and display the map according to the specific location. If the location cannot be determined, then the center of the map should be installed in Moscow.
The problem is that ymaps.geolocation.get works asynchronously and cannot create a map with location coordinates.
In short, what I want to do:
- Create a variable of current location coordinates:
var current_coords = null; - We determine the location coordinates using
ymaps.geolocation.get, if the coordinates are not determined, then we return the coordinates of Moscow - Assign the
current_coordsvariable the coordinates obtained in step 2 - Create and display a map:
var myMap = new ymaps.Map('map', {center: current_coords, zoom: 6}); - Add points to the map, polygon-shaped zones, etc.
It turns out that you have to wait until step 2 works out, and only then perform steps 3-5. I can not understand how this can be implemented.