Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
1  
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

3 Answers 3

up vote 3 down vote accepted

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

share|improve this answer

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;
    return new google.maps.Point(x, y);
};
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))));
    return new google.maps.LatLng(lat, lng);
};

The 256 means the tileSize.

share|improve this answer

Google maps use Mercator Projection (EPSG:3857). The formulas for the projection are:

enter image description here

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.