2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include "scenecoordinate.h"
29 #include "geocoordinate.h"
31 GeoCoordinate::GeoCoordinate() :
35 qDebug() << __PRETTY_FUNCTION__;
38 GeoCoordinate::GeoCoordinate(double latitude, double longitude) :
40 m_longitude(longitude)
42 qDebug() << __PRETTY_FUNCTION__;
45 GeoCoordinate::GeoCoordinate(SceneCoordinate &coordinate)
47 qDebug() << __PRETTY_FUNCTION__;
49 convertFrom(coordinate);
52 void GeoCoordinate::convertFrom(const SceneCoordinate &coordinate)
54 qDebug() << __PRETTY_FUNCTION__;
56 const int MAP_PIXELS_Y = OSM_MAP_MAX_PIXEL_Y + 1;
58 double longitude = coordinate.x() / OMS_MAP_PIXELS_X * 360.0 - 180;
60 double n = M_PI - 2.0 * M_PI * coordinate.y() / MAP_PIXELS_Y;
61 double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
63 setLatitude(latitude);
64 setLongitude(longitude);
67 bool GeoCoordinate::isNull() const
69 qDebug() << __PRETTY_FUNCTION__;
71 if (m_latitude == 0 && m_longitude == 0)
77 double GeoCoordinate::latitude() const
79 qDebug() << __PRETTY_FUNCTION__;
84 double GeoCoordinate::longitude() const
86 qDebug() << __PRETTY_FUNCTION__;
91 void GeoCoordinate::setLatitude(double latitude)
93 qDebug() << __PRETTY_FUNCTION__;
95 m_latitude = latitude;
98 void GeoCoordinate::setLongitude(double longitude)
100 qDebug() << __PRETTY_FUNCTION__;
102 m_longitude = longitude;
105 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate)
107 dbg.nospace() << "(" << coordinate.latitude() << ", " << coordinate.longitude() << ")";