def get_zoom(cls, latitudes, longitudes, size, scale):
"""Compute level of zoom needed to display all points in a single tile.
:param pandas.Series latitudes: set of latitudes
:param pandas.Series longitudes: set of longitudes
:param int size: size of the tile
:param int scale: 1 or 2 (free plan), see Google Static Maps API docs
:return: zoom level
:rtype: int
"""
# Extreme pixels
min_pixel = cls.to_pixel(latitudes.min(), longitudes.min())
max_pixel = cls.to_pixel(latitudes.max(), longitudes.max())
# Longitude spans from -180 to +180, latitudes only from -90 to +90
amplitudes = (max_pixel - min_pixel).abs() * pd.Series([2., 1.], index=['x_pixel', 'y_pixel'])
return int(np.log2(2 * size / amplitudes.max()))
评论列表
文章目录