首页 > 解决方案 > get_bounds() 返回 [[None, None], [None, None]]

问题描述

使用以下代码,我希望获得可见地图角的纬度/经度对:

import folium

testmap = folium.Map(location=[-23.52, 115.5]
                  , zoom_start=7
                  , prefer_canvas=True
                  )

testmap.get_bounds()

相反,我得到:

[[None, None], [None, None]]

我做错了什么?我正在使用来自 master 分支的 Folium,如果这有助于解决这个问题。

标签: python-3.xfolium

解决方案


我也遇到了这个问题,我没有解决方案,但我知道在查看get_bounds()函数的实现时发生了什么。

def get_bounds(self):
    """Computes the bounds of the object and all it's children
    in the form [[lat_min, lon_min], [lat_max, lon_max]].
    """
    bounds = self._get_self_bounds()

    for child in self._children.values():
        child_bounds = child.get_bounds()

def _get_self_bounds(self):
    """Computes the bounds of the object itself (not including it's children)
    in the form [[lat_min, lon_min], [lat_max, lon_max]]
    """
    return [[None, None], [None, None]]

因此,首先计算地图本身的边界(返回 None 值),然后计算孩子的边界。由于在您的示例中没有子级,因此该get_bounds()函数返回[[None, None], [None, None]].


推荐阅读