Convert lat long to X Y coordinates C++ -


this question has answer here:

i have vector full of lat long coordinates in format

82.0000000, -180.0000000 

i trying convert them x , y coordinate plot them map using code, far can see right...

x:

double testclass::getx(double lon) {     // convert long x coordinate (2043 = map width)     double x =  lon;     // scale     x =         x * 2043.0 / 360.0;     // center     x +=        2043.0/2.0;     return x; } 

y:

double testclass::gety(double lat) {     // convert lat y coordinate (1730 = map height)     double y =  -1 * lat;     // scale     y =         y * 1730.0 / 180.0;     // center     y +=        1730.0/2.0;     return y; } 

however when plotted on map can see points resemble world map off x amount , think scaling

any ideas?

ok found answer

double testclass::getx(double lon, int width) {     // width map width     double x = fmod((width*(180+lon)/360), (width +(width/2)));      return x; }  double testclass::gety(double lat, int height, int width) {     // height , width map height , width     double pi = 3.14159265359;     double latrad = lat*pi/180;      // y value     double mercn = log(tan((pi/4)+(latrad/2)));     double y     = (height/2)-(width*mercn/(2*pi));     return y; } 

so yea works when using mercator map


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -