rage
6
Hey Rubke,
I am using the following methods (implemented in C++ with Qt) they work fine.
(I know, they are not implemented performantly ;))
QPoint coordinateToDisplay(Coordinate& coordinate, int zoom)
{
double numberOfTiles = pow(2, zoom);
// LonToX
double x = (coordinate.getLongitude()+180) * (numberOfTiles*tilesize)/360.;
// LatToY
double projection = log(tan(PI/4+deg_rad(coordinate.getLatitude())/2));
double y = (projection /PI);
y = 1-y;
y = y /2 * (numberOfTiles*tilesize);
QPoint point = QPoint(int(x), int(y));
return point;
}
Coordinate displayToCoordinate(const QPoint& point, int zoom)
{
// longitude
double longitude = (point.x()*(360/(pow(2,zoom)*256)))-180;
// latitude
double latitude = point.y()*(2/(pow(2,zoom)*256));
latitude = 1-latitude;
latitude = latitude*PI;
latitude = rad_deg(atan(sinh(latitude)));
Coordinate coord = Coordinate(longitude, latitude);
return coord;
}