【问题标题】:The tile coordinates returned from latlng?从 latlng 返回的瓦片坐标?
【发布时间】:2013-08-15 11:53:01
【问题描述】:

我正在使用这两个函数将 latlng 转换为图块坐标。我无法理解的是,如果在缩放级别 1 有 4 个图块。那么这些坐标属于哪些图块呢?还是这些属于左上角?

public int langtoTileX(Double lng,int zoom)
{
    double x;
    x = Math.round((256*(Math.pow(2,zoom-1)))+(lng*((256*(Math.pow(2,zoom)))/360)));
    return ((int)(x/256));
}
public int lattoTileY(Double lat,int zoom)
{
    Double exp = Math.sin(lat*Math.PI/180);
    if (exp < -.9999)
        exp = -.9999;
    if (exp > .9999)
        exp = .9999 ;
    return (int) (Math.round (256*(Math.pow(2,zoom-1)))+((.5*Math.log((1+exp)/(1-exp)))*((-256*(Math.pow(2,zoom)))/(2*Math.PI))))/256;
}

本例中使用了相同类型的公式:

https://developers.google.com/maps/documentation/javascript/examples/map-coordinates

【问题讨论】:

    标签: android google-maps google-maps-android-api-2


    【解决方案1】:

    很可能是它的左上角图块。当您想要细分地图时,使用四叉树可能很有用,因此在缩放级别 1 处有 4 个图块。查找 bing 地图四键解决方案:http://msdn.microsoft.com/en-us/library/bb259689.aspx。但是 Google 地图使用 x,y 对来表示图块:How can I get Tile Count, Tile X, Tile Y details without specifying zoom Level (or LevelOfDetails)?。在缩放级别 0 中,在缩放级别 1 中有 1 个图块,您可以看到 4 个图块和两侧的一些图块,等等。链接:http://facstaff.unca.edu/mcmcclur/GoogleMaps/Projections/GoogleCoords.htmlhttp://www.maptiler.org/google-maps-coordinates-tile-bounds-projection

    更新:要从 x,y 对中获取边界框,请使用如下矩形 x,x+1,y,y+1: TileProvider method getTile - need to translate x and y to lat/long。但您也可以在 Bing 和 Google 地图之间进行转换。替换四键值如下:0=q, 1=r, 2=t, 3=s (?), 也可能是 0=q, 1=r, 2=s, 3=t (?) 并将其附加到网址http://kh.google.com/kh?v=3&;t=quadkey。来源:http://dzone.com/snippets/converting-between-2-google

    更新2:网址http://kh.google.com已死,但您仍然可以使用sn-p:

        def quadtree(x,y, zoom):
        out = []
        m = {(0,0):'q', (0,1):'t', (1,0):'r', (1,1):'s'}
        for i in range(17-zoom):
            x, rx = divmod(x, 2)
        y, ry = divmod(y, 2)
        out.insert(0, m[(rx,ry)])
            return 't' + ''.join(out)
    
         def xyzoom(quad):
             x, y, z = 0, 0, 17
         m = {'q':(0,0), 't':(0,1), 'r':(1,0), 's':(1,1)}
         for c in quad[1:]:
            x = x*2 + m[c][0]
            y = y*2 + m[c][1]
            z -= 1
         return x, y, z
    

    在地图中,曲线从右上角开始到右下角到左下角到左上角。因此它看起来像一个倒U形?也许我错了,它是左上角,右上角,左下角,右下角?然后是Z形。那么 lat,lng 对在左上角的瓦片中吗?

    为了得到边界框,我假设 long 和 lat 以秒为单位。

    首先,您需要以秒为单位计算矩形的宽度。一秒是赤道上的 30.9 米,对于其他纬度,乘以 cos(lat),因此要将其转换为秒,请执行以下操作:

    double widthSeconds = meters / (30.9 * cos(lat));
    

    第二,知道了盒子的中心,就很容易计算出角的坐标:

    1BoundingBox around a geo coordinate

    【讨论】:

    • 如何获得代表特定纬度的边界区域?
    • 这是另一个问题。如何从 latlong 获取周围的图块?图块的边界框或我需要下载的图块列表来表示 latlong?
    • 我的意思是两个 latlong 点之间的瓦片列表。或者我需要下载两个 latlong 之间的表示区域的瓦片列表?
    • 好的,你能帮我解决这个问题吗? stackoverflow.com/questions/18309524/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多