2010-11-24 3 views
4

두 개의 LatLong 포인트가 있습니다. 사각형의 왼쪽 위와 오른쪽 하단에 Google지도 API를 사용하여이 사각형의 위성 이미지를 검색하고 싶습니다.Google Static Maps API에서 사각형의 이미지 가져 오기

확대/축소 수준이 정수이기 때문에이 정확한 사각형을 얻지 못할 수도 있지만 latlong에서 pixmap에 대한 경계 상자를 계산할 수있는 한 더 큰 pixmap을 얻으면 아무런 문제가 없다는 것을 알고 있습니다. 좌표.

픽스맵 크기가 고정되어 있으므로 (640x640이라고 가정 해 봅시다) 적절한 줌 레벨을 찾고 픽스맵의 경계 상자를 계산하는 방법을 중심으로합니까?

답변

2

CalculateBoundsZoomLevel 함수를 제공하는 이전 Google Maps API 블로그에 링크 된 Python 참조를 찾았습니다.

소스 파일은 here입니다.

def CalculateBoundsZoomLevel(self, bounds, view_size): 
    """Given lat/lng bounds, returns map zoom level. 

    This method is used to take in a bounding box (southwest and northeast 
    bounds of the map view we want) and a map size and it will return us a zoom 
    level for our map. We use this because if we take the bottom left and 
    upper right on the map we want to show, and calculate what pixels they 
    would be on the map for a given zoom level, then we can see how many pixels 
    it will take to display the map at this zoom level. If our map size is 
    within this many pixels, then we have the right zoom level. 

    Args: 
     bounds: A list of length 2, each holding a list of length 2. It holds 
     the southwest and northeast lat/lng bounds of a map. It should look 
     like this: [[southwestLat, southwestLat], [northeastLat, northeastLng]] 
     view_size: A list containing the width/height in pixels of the map. 

    Returns: 
     An int zoom level. 
    """ 
    zmax = 18 
    zmin = 0 
    bottom_left = bounds[0] 
    top_right = bounds[1] 
    backwards_range = range(zmin, zmax) 
    backwards_range.reverse() 
    for z in backwards_range: 
     bottom_left_pixel = self.FromLatLngToPixel(bottom_left, z) 
     top_right_pixel = self.FromLatLngToPixel(top_right, z) 
     if bottom_left_pixel.x > top_right_pixel.x : 
     bottom_left_pixel.x -= self.CalcWrapWidth(z) 
     if abs(top_right_pixel.x - bottom_left_pixel.x) <= view_size[0] \ 
      and abs(top_right_pixel.y - bottom_left_pixel.y) <= view_size[1] : 
     return z 
    return 0 
관련 문제