2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
6 Sami Rämö - sami.ramo@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #include "scenecoordinate.h"
30 #include "geocoordinate.h"
32 GeoCoordinate::GeoCoordinate() :
36 qDebug() << __PRETTY_FUNCTION__;
39 GeoCoordinate::GeoCoordinate(double latitude, double longitude) :
41 m_longitude(longitude)
43 qDebug() << __PRETTY_FUNCTION__;
46 GeoCoordinate::GeoCoordinate(const SceneCoordinate &coordinate)
48 qDebug() << __PRETTY_FUNCTION__;
50 convertFrom(coordinate);
53 void GeoCoordinate::convertFrom(const SceneCoordinate &coordinate)
55 qDebug() << __PRETTY_FUNCTION__;
57 const int MAP_PIXELS_Y = OSM_MAP_MAX_PIXEL_Y + 1;
59 double longitude = coordinate.x() / OMS_MAP_PIXELS_X * 360.0 - 180;
61 double n = M_PI - 2.0 * M_PI * coordinate.y() / MAP_PIXELS_Y;
62 double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
64 setLatitude(latitude);
65 setLongitude(longitude);
68 bool GeoCoordinate::isNull() const
70 qDebug() << __PRETTY_FUNCTION__;
72 if (m_latitude == 0 && m_longitude == 0)
78 bool GeoCoordinate::isValid()
80 qDebug() << __PRETTY_FUNCTION__;
82 const double MAX_LATITUDE = 90;
83 const double MIN_LATITUDE = -90;
84 const double MIN_LONGITUDE = -180.0;
85 const double MAX_LONGITUDE = 180.0;
87 if ((m_latitude >= MIN_LATITUDE) && (m_latitude < MAX_LATITUDE) &&
88 (m_longitude >= MIN_LONGITUDE) && (m_longitude < MAX_LONGITUDE))
95 double GeoCoordinate::latitude() const
97 qDebug() << __PRETTY_FUNCTION__;
102 double GeoCoordinate::longitude() const
104 qDebug() << __PRETTY_FUNCTION__;
109 void GeoCoordinate::setLatitude(double latitude)
111 qDebug() << __PRETTY_FUNCTION__;
113 m_latitude = latitude;
116 void GeoCoordinate::setLongitude(double longitude)
118 qDebug() << __PRETTY_FUNCTION__;
120 m_longitude = longitude;
123 QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate)
125 out << coordinate.m_latitude << coordinate.m_longitude;
129 QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate)
131 in >> coordinate.m_latitude >> coordinate.m_longitude;
135 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate)
137 dbg.nospace() << "(" << coordinate.latitude() << ", " << coordinate.longitude() << ")";