Java tutorial
//package com.java2s; //License from project: Apache License import java.awt.geom.Point2D; public class Main { /** * Returns the lat/lng as an "Offset Normalized Mercator" pixel coordinate, * this is a coordinate that runs from 0..1 in latitude and longitude with 0,0 being * top left. Normalizing means that this routine can be used at any zoom level and * then multiplied by a power of two to get actual pixel coordinates. */ public static Point2D toNormalisedPixelCoords(double lat, double lng) { // first convert to Mercator projection // first convert the lat lon to mercator coordintes. if (lng > 180) { lng -= 360; } lng /= 360; lng += 0.5; lat = 0.5 - ((Math.log(Math.tan((Math.PI / 4) + ((0.5 * Math.PI * lat) / 180))) / Math.PI) / 2.0); return new Point2D.Double(lng, lat); } }