开发者

Getting Y position from Latitude on a spherical projected map

In Javascript.

I have a map of the world that is 1024 x 1024px - It is a spherical Mercator projection.

Im looking to convert long/lat to x,y for this map. I have a bunch of coordinates that I need to overlay on top of it.

Calculating longitude was very easy, and I am doing it like so:

pos.x = ((long + 180)/ 360)开发者_运维百科 * 1024;

I just need to same for lat --> y

I looked around a saw a lot of reference to openlayers, but didn't see such a conversion.


To boil it down:

var mercator = function(lat, lng) {
  return [lng, Math.log( (Math.sin(lat) + 1.0) / Math.cos(lat)) ] ;
};

Lat and long must be expressed in radians of course.


You can find the corresponding formulas in this wikipedia article: Mercator Projection.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜