D
D
Dmitry Kim2016-04-22 14:16:53
Yandex
Dmitry Kim, 2016-04-22 14:16:53

How to properly center and zoom the coordinate area on Yandex.Map?

There are several coordinates (the number varies). They need to be displayed on Yandex.Map in such a way that the zoom is maximum, and at the same time all the coordinates lie on the visible part of the map.
What I do: I go over all the coordinates, collect the minima and maxima of both longitude and latitude. It turns out a certain rectangle, all the coordinates of our points will certainly be inside or on the borders of this rectangle. Then I take its center - this will be the center of our map. It's logical and not difficult.
The snag is that setting Zoom manually is not an option. The points may remain in the center and there will be a lot of empty space, or some point will be outside the visibility of our map window.
How to do it right? I can’t find in the docks how and what to pull, but I know that somewhere it is.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2016-04-22
@kimono

What you counted is called bounds. And judging by the docks, there is a certain getMapZoom method, which for a given area will calculate the necessary zoom for you so that everything fits.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question