Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (46 sloc) 1.532 kb
418ce8ae »
2011-04-14 initial commit
1 /*
2 * geoposition.cpp
3 * Copyright (C) 2011 Nicolas Martin, Université de Montréal
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "geoposition.h"
20
527e4ab5 »
2011-04-17 Added distance calculation and disabled next button
21 #include <cmath>
22
418ce8ae »
2011-04-14 initial commit
23 GeoPosition::GeoPosition(qreal lat, qreal lon) :
24 lat(lat), lon(lon)
25 {
26 }
27
527e4ab5 »
2011-04-17 Added distance calculation and disabled next button
28
29 qreal toRad(double deg) {
30 return deg * M_PI / 180.0;
31 }
32
33 qreal GeoPosition::distanceFrom(GeoPosition *other) {
34 qreal R = 6371; // Diameter of the Earth
35 qreal lat1 = toRad(this->getLat()),
36 lat2 = toRad(other->getLat()),
37 lon1 = toRad(this->getLon()),
38 lon2 = toRad(other->getLon());
39 return acos(sin(lat1) * sin(lat2) +
40 cos(lat1) * cos(lat2) *
41 cos(lon2 - lon1)) * R;
42 }
43
418ce8ae »
2011-04-14 initial commit
44 QDataStream& operator<<(QDataStream &ds, const GeoPosition &pos)
45 {
46 ds << pos.lat << pos.lon;
47 return ds;
48 }
49
50 QDataStream& operator>>(QDataStream &ds, GeoPosition &pos)
51 {
52 ds >> pos.lat >> pos.lon;
53 return ds;
54 }
Something went wrong with that request. Please try again.