I
I
Inn2018-11-24 18:04:39
MODX
Inn, 2018-11-24 18:04:39

Why is MODX REVO not displaying object coordinates on Yandex map?

Hello!
After transferring the site to the hosting, objects are not displayed on Yandex maps.
For objects, a TV-parameter contacts_address has been created (a text field in which an address is entered).
The map is displayed in a chunk:

<script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>
<script type="text/javascript">
    ymaps.ready(init);
    var myMap;

    function init() {
        myMap = new ymaps.Map("map", {
            center: ,
            controls: ['zoomControl'],
            zoom: 16
        });
        
        var myPlacemark = new ymaps.Placemark(, {
            hintContent: 'MODX Revolution',
            balloonContent: ''
        });
        myMap.geoObjects.add(myPlacemark);
    }
</script>
<div class="map" id="map" style="width:100%; height:250px; margin-top:15px;"></div>

get_coord snippet:
<?php
if($addr) {
    $json = file_get_contents('http://geocode-maps.yandex.ru/1.x/?format=json&geocode='.$addr);
    $ar = json_decode($json, true);

    $pos = $ar['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos'];
    $temp = explode(" ", $pos);
    return '[' . "{$temp[1]}, {$temp[0]}" . ']';
}

Made according to the example: modx.ru/novosti-i-stati/article/261
When viewing the source code of the page, it can be seen that the coordinates are not transmitted:
<script type="text/javascript">
    ymaps.ready(init);
    var myMap;

    function init() {
        myMap = new ymaps.Map("map", {
            center: [, ],
            controls: ['zoomControl'],
            zoom: 16
        });
        
        var myPlacemark = new ymaps.Placemark([, ], {
            hintContent: 'ООО',
            balloonContent: 'Саратов, ул. Астраханская, д.1'
        });
        myMap.geoObjects.add(myPlacemark);
    }
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2018-11-24
@ruslan_aleev

Hello, I transfer coordinates to the map via TV like this:
center: [ ],, I noticed that it doesn’t work without spaces, i.e. add spaces in the get_coord: snippet to return '[ ' . "{$temp[1]}, {$temp[0]}" . ' ]';.
Also try to call TV with coordinates in the map, without a snippet, there may be an error in the map script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question