How to get bounds of a google static map?

后端 未结 5 1847
自闭症患者
自闭症患者 2020-12-05 01:07

How to get bounds in degrees of google static map which has been returned, for example, for following request

http://maps.googleapis.com/maps/api/staticmap?c         


        
5条回答
  •  难免孤独
    2020-12-05 01:53

    For big zoom factors (>=8), where non-uniformity of map scale on y axis can be neglected, there is much easier method, where we just takes into accout 1/cos(latitude) correction for pixels/(degrees of latitude) resolution. Initial resolution for zoom=0 is 256 pixels per 360 degrees both for x and y at 0 lattitude.

    def get_static_map_bounds(lat, lng, zoom, sx, sy):
        # lat, lng - center
        # sx, sy - map size in pixels
    
        # 256 pixels - initial map size for zoom factor 0
        sz = 256 * 2 ** zoom
    
        #resolution in degrees per pixel
        res_lat = cos(lat * pi / 180.) * 360. / sz
        res_lng = 360./sz
    
        d_lat = res_lat * sy / 2
        d_lng = res_lng * sx / 2
    
        return ((lat-d_lat, lng-d_lng), (lat+d_lat, lng+d_lng))
    

提交回复
热议问题