A
A
Alexander K2014-05-28 08:18:45
API
Alexander K, 2014-05-28 08:18:45

How to implement an adaptive api Yandex map on the site?

Hello.
I have a task to place the location of a place on the site using the Yandex Maps API. I did it, but on mobile devices it looks terrible, the map crawls out of the display. How can I make the map size adapt to mobile devices?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
G
ghost23, 2015-03-16
@ghost23

Use css

#map {
        width: 640px; height: 600px;
}
@media (max-width: 320px) {
      #map {
        width: 260px; height: 300px;
      }
}

Even when loading, you can determine the size of the window using javascript and put the necessary parameters in the Yandex Maps script.
example with jquery
var viewport = {
    width : $(window).width(),
    height : $(window).height()
};
var width = viewport.width;
var height = viewport.height;

if (width > 1000) {
var zoomval = 13;
} else {
var zoomval = 12;
}

function init() {
    myMap = new ymaps.Map("map", {
        center: [55.555555, 33.333333],
        zoom: zoomval,
        });
}

A
Albert Rashitov, 2014-06-25
@albert_rar

The author of the question did not find the answer? If you found it, could you share it?

A
Alexander K, 2014-06-25
@privetizkosmosa

I didn’t understand Yandex maps, I found a solution with google map

R
Rager, 2015-06-06
@Rager

You just need to replace the fixed width and height with "auto" in the code that you insert on the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question