地理坐标系与瓦片坐标系相互转换

//将tile(瓦片)坐标系转换为lnglat(地理)坐标系
public static Lnglat toLnglat(Tile tile) {
        double n = Math.pow(2, tile.getZoom());
        double lng = tile.getX() / n * 360.0 - 180.0;
        double lat = Math.atan(Math.sinh(Math.PI * (1 - 2 * tile.getY() / n)));
        lat = lat * 180.0 / Math.PI;
        return new Lnglat(lng, lat);
 }
  
//将lnglat地理坐标系转换为tile瓦片坐标系
public static Tile toTile(int zoom, Lnglat lnglat) {
        double n = Math.pow(2, zoom);
        double tileX = ((lnglat.getLng() + 180) / 360) * n;
        double tileY = (1 - (Math.log(Math.tan(Math.toRadians(lnglat.getLat())) + (1 / Math.cos(Math.toRadians(lnglat.getLat())))) / Math.PI)) / 2 * n;
        return new Tile(new Double(tileX).intValue(), new Double(tileY).intValue(), zoom);
}

 

posted @ 2017-08-01 13:59  Redchar  阅读(1907)  评论(0编辑  收藏  举报