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 bool GeoCoordinate::m_metaTypeIsRegistered = false;
34 GeoCoordinate::GeoCoordinate() :
37 m_validityFlags(NoCoordinatesSet)
39 qDebug() << __PRETTY_FUNCTION__;
44 GeoCoordinate::GeoCoordinate(double latitude, double longitude)
46 qDebug() << __PRETTY_FUNCTION__;
50 setLatitude(latitude);
51 setLongitude(longitude);
54 GeoCoordinate::GeoCoordinate(const SceneCoordinate &coordinate)
56 qDebug() << __PRETTY_FUNCTION__;
60 convertFrom(coordinate);
63 void GeoCoordinate::convertFrom(const SceneCoordinate &coordinate)
65 qDebug() << __PRETTY_FUNCTION__;
67 const int MAP_PIXELS_Y = OSM_MAP_MAX_PIXEL_Y + 1;
69 double longitude = coordinate.x() / OMS_MAP_PIXELS_X * 360.0 - 180;
71 double n = M_PI - 2.0 * M_PI * coordinate.y() / MAP_PIXELS_Y;
72 double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
74 setLatitude(latitude);
75 setLongitude(longitude);
78 bool GeoCoordinate::isNull() const
80 qDebug() << __PRETTY_FUNCTION__;
82 if ((m_latitude == 0) && (m_longitude == 0))
88 bool GeoCoordinate::isValid()
90 qDebug() << __PRETTY_FUNCTION__;
92 const double MAX_LATITUDE = 90;
93 const double MIN_LATITUDE = -90;
94 const double MIN_LONGITUDE = -180.0;
95 const double MAX_LONGITUDE = 180.0;
97 if ((m_validityFlags & LatitudeSet) && (m_validityFlags & LongitudeSet) &&
98 (m_latitude >= MIN_LATITUDE) && (m_latitude <= MAX_LATITUDE) &&
99 (m_longitude >= MIN_LONGITUDE) && (m_longitude <= MAX_LONGITUDE))
106 double GeoCoordinate::latitude() const
108 qDebug() << __PRETTY_FUNCTION__;
113 double GeoCoordinate::longitude() const
115 qDebug() << __PRETTY_FUNCTION__;
120 void GeoCoordinate::registerMetaType()
122 qDebug() << __PRETTY_FUNCTION__;
124 if (!m_metaTypeIsRegistered) {
125 qRegisterMetaType<GeoCoordinate>("GeoCoordinate");
126 qRegisterMetaTypeStreamOperators<GeoCoordinate>("GeoCoordinate");
127 m_metaTypeIsRegistered = true;
131 void GeoCoordinate::setLatitude(double latitude)
133 qDebug() << __PRETTY_FUNCTION__;
135 m_latitude = latitude;
136 m_validityFlags |= LatitudeSet;
139 void GeoCoordinate::setLongitude(double longitude)
141 qDebug() << __PRETTY_FUNCTION__;
143 m_longitude = longitude;
144 m_validityFlags |= LongitudeSet;
147 QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate)
149 out << coordinate.m_latitude << coordinate.m_longitude;
153 QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate)
155 in >> coordinate.m_latitude >> coordinate.m_longitude;
159 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate)
161 dbg.nospace() << "(" << coordinate.latitude() << ", " << coordinate.longitude() << ")";