import math def lonlat2tile(lon, lat, z): tile_count = 1 << z x = int((lon + 180.0) / 360.0 * tile_count) lat_rad = math.radians(lat) y = int((1.0 - math.log(math.tan(lat_rad) + 1/math.cos(lat_rad)) / math.pi) / 2.0 * tile_count) return x, y # 你的范围、层级 z = 15 ul_lon, ul_lat = 120.0, 32.0 lr_lon, lr_lat = 120.5, 31.5 x1, y1 = lonlat2tile(ul_lon, ul_lat, z) x2, y2 = lonlat2tile(lr_lon, lr_lat, z) tile_w = abs(x2 - x1) + 1 tile_h = abs(y2 - y1) + 1 pixel_w = tile_w * 256 pixel_h = tile_h * 256 print(f"横向瓦片数: {tile_w} 像素SizeX={pixel_w}") print(f"纵向瓦片数: {tile_h} 像素SizeY={pixel_h}")