0

I need use mercator projection to point the places by latitude and logitude in my svg application.I have serached a lot and i got these links,

http://en.wikipedia.org/wiki/Mercator_projection
Covert latitude/longitude point to a pixels (x,y) on mercator projection

CODE

            //this lat and long is for chicago
            var latitude = 41.850033; // (φ)
            var longitude = -87.65005229999997;   // (λ)

            var PI = 3.14;
            var mapWidth = 750;
            var mapHeight = 380;

            // get x value
            var x = (mapWidth * (180+longitude) / 360) % mapWidth + (mapWidth / 2);

            // convert from degrees to radians
            var latRad = latitude * PI / 180;

            // get y value
            var mercN = Math.log(Math.tan((PI / 4) + (latRad / 2)));
            var y = (mapHeight / 2) - (mapWidth * mercN / (2 * PI));

I've used this code in my application, but it doesn't work for me.
Please help to get x and y position from the latitude and longitude. Any Suggestions should be appreciated.

Community
  • 1
  • 1
Karthi Keyan
  • 4,243
  • 5
  • 24
  • 47

1 Answers1

0

You forgot the top left and bottom right corner of the map and the factor to multiply the x,y coordinates to give the correct map projection. You can use a fixed map coordinate, i.e. a factor or you can compute the bounding box:Convert lat/lon to pixel coordinate? and then compute the world width and height that fits the map's width and height.

Community
  • 1
  • 1
Micromega
  • 12,486
  • 7
  • 35
  • 72