Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static long[] getTileFromGeo(double lat, double lon, int zoom) {
        double rLon, rLat, a, k, z;
        rLon = lon * Math.PI / 180;
        rLat = lat * Math.PI / 180;
        a = 6378137;
        k = 0.0818191908426;
        z = Math.pow(Math.tan(Math.PI / 4 + rLat / 2) / (Math.tan(Math.PI / 4 + Math.asin(k * Math.sin(rLat)) / 2)),
                k);
        return new long[] { (int) (((20037508.342789 + a * rLon) * 53.5865938 / Math.pow(2, (23 - zoom))) / 256),
                (int) (((20037508.342789 - a * Math.log(z)) * 53.5865938 / Math.pow(2, (23 - zoom)))) / 256 };
    }
}