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,
24 #ifndef GEOCOORDINATE_H
25 #define GEOCOORDINATE_H
30 class SceneCoordinate;
33 * @brief Geographic coordinate
35 * @author Jussi Laitinen - jussi.laitinen@ixonos.com
36 * @author Sami Rämö - sami.ramo@ixonos.com
42 * @brief Constructs a null coordinate
47 * @brief Constructs a coordinate with given latitude and longitude values
49 * @param latitude Latitude value
50 * @param longitude Longitude value
52 GeoCoordinate(double latitude, double longitude);
55 * @brief Constructs a coordinate with values converted from the given SceneCoordinate
57 * @param coordinate Scene coordinate
59 GeoCoordinate(const SceneCoordinate &coordinate);
61 /*******************************************************************************
62 * MEMBER FUNCTIONS AND SLOTS
63 ******************************************************************************/
66 * @brief Distance to other coordinate
68 * This calculation returns the great-circle distance between the two coordinates, with an
69 * assumption that the Earth is spherical. Calculation is done using haversine formula. Altitude
70 * is not used in the calculation.
72 * @param other Coordinate where the distance is calculated from this coordinate
73 * @returns Distance to other coordinate (in meters)
75 qreal distanceTo(const GeoCoordinate &other) const;
78 * @brief Check if coordinate is (0.0, 0.0)
80 * @returns True if both latitude and longitude are 0.0, otherwise false
85 * @brief Check if coordinate is valid.
87 * Latitude and longitude values must be set, latitude must be -90..90 and longitude must
88 * be -180..180 for valid coordinate.
90 * @return true if coordinate is valid, false otherwise
95 * @brief Returns the latitude value
99 double latitude() const;
102 * @brief Returns the longitude value
106 double longitude() const;
109 * @brief Sets the latitude
111 * @param latitude Latitude value
113 void setLatitude(double latitude);
116 * @brief Sets the longitude
118 * @param longitude Longitude value
120 void setLongitude(double longitude);
124 * @brief Convert values from SceneCoordinate
126 * @param coordinate Scene coordinate
128 void convertFrom(const SceneCoordinate &coordinate);
131 * @brief Register meta type and stream operators for using the class with QVariant and QSetting
133 * Registering is done only once at the first time the GeoCoordinate object is constructed.
135 void registerMetaType();
137 /*******************************************************************************
139 ******************************************************************************/
144 * @brief Flag values for coordinate validity
147 NoCoordinatesSet = 0x0,
152 static bool m_metaTypeIsRegistered; ///< Is the meta type already registered?
153 double m_latitude; ///< Latitude value
154 double m_longitude; ///< Longitude value
155 int m_validityFlags; ///< Coordinate validity flags
157 /*******************************************************************************
159 ******************************************************************************/
162 * @brief Subtract operator
164 * @returns Returns a GeoCoordinate object that is formed by subtracting coordinate2 from
165 * coordinate1. Each component is subtracted separately.
167 friend const GeoCoordinate operator-(const GeoCoordinate &coordinate1,
168 const GeoCoordinate &coordinate2);
171 * @brief Output operator
173 * @param out Output stream
174 * @param coordinate Coordinate object which is written to the stream
176 friend QDataStream &operator<<(QDataStream &out, const GeoCoordinate &coordinate);
179 * @brief Input operator
181 * @param in Input stream
182 * @param coordinate Object where the values from the stream are saved
184 friend QDataStream &operator>>(QDataStream &in, GeoCoordinate &coordinate);
187 QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate);
189 Q_DECLARE_METATYPE(GeoCoordinate)
191 #endif // GEOCOORDINATE_H