# What is the formula for calculating world coordinates for a given LatLng in Google maps?

I want to calculate a given LatLng to the world coordinate .

I know I can use the internal projection of Google maps like this:

``````var map=new google.maps.Map(...);
map.getProjection().fromLatLngToPoint(latlng);
``````

But I want the formula to calculate, rather then the result.

-
I've clarified the question to indicate that you require the forumla. – Devdatta Tengshe Jul 17 '13 at 3:17
@DevdattaTengshe: Thanks, that's what I want. – giser Jul 17 '13 at 5:34

Openstreetmap uses the same tile naming as Google Maps. You find a lot of formulas to calculate them here: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames

-

According to links provided by `Andre Joost`, I found the translation. And this is the projection for google.maps:

``````function MProjection() {
}
MProjection.prototype.fromLatLngToPoint = function(latlng) {
var x = (latlng.lng() + 180) / 360 * 256;
var y = ((1 - Math.log(Math.tan(latlng.lat() * Math.PI / 180) + 1 / Math.cos(latlng.lat() * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, 0)) * 256;
};
MProjection.prototype.fromPointToLatLng = function(point) {
var lng = point.x / 256 * 360 - 180;
var n = Math.PI - 2 * Math.PI * point.y / 256;
var lat = (180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))));
The `256` means the tileSize.
where `lambda` is longitude, `phi` is latitude. `Lambda0` is a constant you have to find out (possibly 0 or +-180 equivalent or something (you can figure out easily). Source: https://en.wikipedia.org/wiki/Mercator_projection#Derivation_of_the_Mercator_projection