Java tutorial
//package com.java2s; public class Main { public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int[] out = new int[2]; final double E2 = (double) aLat * Math.PI / 180; final long sradiusa = 6378137; final long sradiusb = 6356752; final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2 - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2; final double B2 = (double) (1 << zoom); out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI); out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return out; } }