V
V
Vladislav Balabanovich2015-10-18 14:57:08
API
Vladislav Balabanovich, 2015-10-18 14:57:08

Yandex map not scalable?

Dynamically create a map:

ymaps.ready(init);
                    var myMap,
                            myPlacemark;

                    function init() {
                        myMap = new ymaps.Map("map", {
                            center: [{{ $event->lat }}, {{ $event->long }}],
                            zoom: 10
                        });
                        ymaps.geocode('Россия, {{ $city }}, {{ $event->address }}', {
                            results: 1
                        }).then(function (res) {
                            var firstGeoObject = res.geoObjects.get(0),
                                    coords = firstGeoObject.geometry.getCoordinates(),
                                    bounds = firstGeoObject.properties.get('boundedBy');

                            myMap.geoObjects.add(firstGeoObject);
                            myMap.setBounds(bounds, {
                                checkZoomRange: true
                            });
                        });
                    }

The map is created correctly, but does not scale, it looks like this -
5334e18dc6.jpg
I understand that the matter is in the geocode asynchronous method, but I do not understand how to make the zoom work properly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2015-10-19
@healqq

Try to get the coordinates of the required area using the getBounds function of the
Yandex Maps
API. It should look something like this:

//после добавления объекта
var bounds = myMap.geoObjects.getBounds();
myMap.setBounds(bounds, {
     checkZoomRange: true
});

In general, what do you want to do? You have one point displayed. If you want the map to be centered on this point with a decent zoom - set the center and zoom yourself. ( setCenter and setZoom methods).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question