E
E
EVOSandru62015-08-12 08:23:28
Yandex
EVOSandru6, 2015-08-12 08:23:28

How to correctly insert several GeoObjects into a Yandex map?

Good afternoon, I
followed the documentation, Placemark normally gets into the map, but GeoObject does not get up (

var lat = <?php echo $lat;?>,
lon = <?php echo $lon;?>;

    ymaps.ready(init);

    var myMap, myPlacemark;

    function init()
    {
        myMap = new ymaps.Map("map",
        {
            center: [lat, lon],
            zoom: 15
        });
        myPlacemark =  new ymaps.Placemark([lat,lon],
        {
            hintContent: '<?php echo $region['country'];?> | <?php echo $region['city'];?>',
            // надпись снизу
            balloonContent: 'Вы на карте'
        });
        // myMap.geoObjects.add(myPlacemark); // Если раскоментить, то метка отображается.


         // Тут проблемка
        // новый геообъект
        var myGeoObject = new ymaps.GeoObject(
        {
            type: 'Point',
            coordinates: [lat, lon]  // 55.8, 37.8   //  43.25063225, 76.93755332
        });

        myMap.geoObjects.add(myGeoObject); // не вставляется

    }

What could be the reason for the error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ostin, 2015-08-12
@EVOSandru6

For a GeoObject, the coordinates and type are described inside the geometry property

var myGeoObject = new ymaps.GeoObject({
    geometry: {
        type: 'Point',
        coordinates: [lat, lon]  // 55.8, 37.8   //  43.25063225, 76.93755332
    }
});

https://tech.yandex.ru/maps/jsbox/2.1/placemark

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question