C
C
consweb2022-04-12 15:25:55
JavaScript
consweb, 2022-04-12 15:25:55

Yandex maps are not loading on the site - what is the reason?

Hello! I can not understand what is the reason - instead of a map, there is just a white area. No controls, no map itself. The script first displays the data from the list element into an array, and it is substituted into the coordinates of the map center.
Here is the code:

<script type="text/javascript">
    window.onload = function() {
        var listInnerText = document.querySelector('.mh-estate__list__inner').innerText; 
        var localizationMatch = listInnerText.match(/Локализация: [\d\.]+,[\d\.]+/); 
        var coordinatesArray = []; 
        
        if (localizationMatch !== null && localizationMatch > 0) { 
            stringCoordinatesArray = localizationMatch[0].split(': ')[1].split(',');
            coordinatesArray = stringCoordinatesArray.map(item => parseFloat(item));

            ymaps.ready(init); 
        
            function init() { 
                var myMap = new ymaps.Map("map", { 
                    center: coordinatesArray,
                    zoom: 7 
                });    
            }
        }
    };
</script>

Here is the container:
<div id="map" style="width: 100%; height: 350px;"></div>

Here is an example of a page: https://cvetoch.ru/properties/dom-315-kv-m-8-sot/
Guys, I will be very grateful if someone tells me!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
consweb, 2022-04-12
@consweb

So looked already - the console of errors does not produce.

C
CryptBomj, 2022-04-12
@CryptBomj

I may not quite understand the essence of the problem, but I will try to help. Isn't it easier to fill in the location of the object in Yandex, and then copy the code from there and do whatever you want with it?

<div style="position:relative;overflow:hidden;"><a href="https://yandex.by/maps?utm_medium=mapframe&utm_source=maps" style="color:#eee;font-size:12px;position:absolute;top:0px;">Яндекс Карты</a><a href="https://yandex.by/maps/geo/selo_ushcherpye/53004489/?from=mapframe&ll=31.883046%2C52.716465&utm_medium=mapframe&utm_source=maps&z=14" style="color:#eee;font-size:12px;position:absolute;top:14px;">село Ущерпье</a><iframe src="https://yandex.by/map-widget/v1/-/CCUFARazgD" width="560" height="400" frameborder="1" allowfullscreen="true" style="position:relative;"></iframe></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question