Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static double tile2lat(int y, int aZoom) {

        final double MerkElipsK = 0.0000001;
        final long sradiusa = 6378137;
        final long sradiusb = 6356752;
        final double FExct = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
        final int TilesAtZoom = 1 << aZoom;
        double result = (y - TilesAtZoom / 2) / -(TilesAtZoom / (2 * Math.PI));
        result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180 / Math.PI;
        double Zu = result / (180 / Math.PI);
        double yy = ((y) - TilesAtZoom / 2);

        double Zum1 = Zu;
        Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
                / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                        * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
        while (Math.abs(Zum1 - Zu) >= MerkElipsK) {
            Zum1 = Zu;
            Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
                    / (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI)))
                            * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
        }

        result = Zu * 180 / Math.PI;

        return result;

    }
}