2016-10-24 00:21:40 +02:00
|
|
|
#include "wgs84.h"
|
|
|
|
#include "coordinates.h"
|
|
|
|
|
2018-04-13 21:14:12 +02:00
|
|
|
double Coordinates::distanceTo(const Coordinates &c) const
|
2016-10-24 00:21:40 +02:00
|
|
|
{
|
2018-04-13 21:14:12 +02:00
|
|
|
double dLat = deg2rad(c.lat() - _lat);
|
|
|
|
double dLon = deg2rad(c.lon() - _lon);
|
|
|
|
double a = pow(sin(dLat / 2.0), 2.0)
|
2016-10-24 00:21:40 +02:00
|
|
|
+ cos(deg2rad(_lat)) * cos(deg2rad(c.lat())) * pow(sin(dLon / 2.0), 2.0);
|
|
|
|
|
|
|
|
return (WGS84_RADIUS * (2.0 * atan2(sqrt(a), sqrt(1.0 - a))));
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
|
|
|
QDebug operator<<(QDebug dbg, const Coordinates &c)
|
|
|
|
{
|
2020-01-22 22:36:58 +01:00
|
|
|
dbg.nospace() << qSetRealNumberPrecision(10) << "Coordinates(" << c.lat()
|
|
|
|
<< ", " << c.lon() << ")";
|
2018-02-13 23:03:18 +01:00
|
|
|
return dbg.space();
|
|
|
|
}
|
|
|
|
#endif // QT_NO_DEBUG
|