17QT_IMPL_METATYPE_EXTERN(QGeoCoordinate)
19static const double qgeocoordinate_EARTH_MEAN_RADIUS = 6371.0072;
22QGeoCoordinatePrivate::QGeoCoordinatePrivate():
28QGeoCoordinatePrivate::QGeoCoordinatePrivate(
const QGeoCoordinatePrivate &other)
35QGeoCoordinatePrivate::~QGeoCoordinatePrivate()
39QGeoMercatorCoordinatePrivate::QGeoMercatorCoordinatePrivate():
40 QGeoCoordinatePrivate(),
45QGeoMercatorCoordinatePrivate::QGeoMercatorCoordinatePrivate(
const QGeoMercatorCoordinatePrivate &other)
46 : QGeoCoordinatePrivate(other),
47 m_mercatorX(other.m_mercatorX),
48 m_mercatorY(other.m_mercatorY)
51QGeoMercatorCoordinatePrivate::~QGeoMercatorCoordinatePrivate()
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
80
81
82
83
84
85
86
89
90
91
92
93
94
95
96
97
98
99
100
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
139
140
141
142
143
144
145
146
147
148
151
152
153
154
155
156
157
158
159
160
161
164
165
166
167QGeoCoordinate::QGeoCoordinate()
168 : d(
new QGeoCoordinatePrivate)
173
174
175
176
177
178
179
180
181QGeoCoordinate::QGeoCoordinate(
double latitude,
double longitude)
182 : d(
new QGeoCoordinatePrivate)
184 if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
191
192
193
194
195
196
197
198
199
200
201
202QGeoCoordinate::QGeoCoordinate(
double latitude,
double longitude,
double altitude)
203 : d(
new QGeoCoordinatePrivate)
205 if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
213
214
215QGeoCoordinate::QGeoCoordinate(
const QGeoCoordinate &other)
220
221
222
223
224
225
226
227
228
231
232
233QGeoCoordinate &QGeoCoordinate::operator=(
const QGeoCoordinate &other)
243
244
245
246
247
248
249
250
251
252
255
256
257QGeoCoordinate::~QGeoCoordinate()
261QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoCoordinatePrivate)
264
265
266
267
268
269
270
271
274
275
276
277
278
279
282
283
284
285
288
289
290bool QGeoCoordinate::isValid()
const
292 CoordinateType t = type();
293 return t == Coordinate2D || t == Coordinate3D;
297
298
299QGeoCoordinate::CoordinateType QGeoCoordinate::type()
const
301 if (QLocationUtils::isValidLat(d->lat)
302 && QLocationUtils::isValidLong(d->lng)) {
307 return InvalidCoordinate;
312
313
314
315
316
317
318
319
320double QGeoCoordinate::latitude()
const
326
327
328
329
330
331
332
333void QGeoCoordinate::setLatitude(
double latitude)
339
340
341
342
343
344
345
346
347double QGeoCoordinate::longitude()
const
353
354
355
356
357
358
359
360void QGeoCoordinate::setLongitude(
double longitude)
366
367
368
369
370
371
372double QGeoCoordinate::altitude()
const
378
379
380
381
382void QGeoCoordinate::setAltitude(
double altitude)
388
389
390
391
392
393
394
395
396
397
398qreal QGeoCoordinate::distanceTo(
const QGeoCoordinate &other)
const
400 if (type() == QGeoCoordinate::InvalidCoordinate
401 || other.type() == QGeoCoordinate::InvalidCoordinate) {
406 double dlat = qDegreesToRadians(other.d->lat - d->lat);
407 double dlon = qDegreesToRadians(other.d->lng - d->lng);
408 double haversine_dlat = sin(dlat / 2.0);
409 haversine_dlat *= haversine_dlat;
410 double haversine_dlon = sin(dlon / 2.0);
411 haversine_dlon *= haversine_dlon;
412 double y = haversine_dlat
413 + cos(qDegreesToRadians(d->lat))
414 * cos(qDegreesToRadians(other.d->lat))
416 double x = 2 * asin(sqrt(y));
417 return qreal(x * qgeocoordinate_EARTH_MEAN_RADIUS * 1000);
421
422
423
424
425
426
427
428
429
430
431qreal QGeoCoordinate::azimuthTo(
const QGeoCoordinate &other)
const
433 if (type() == QGeoCoordinate::InvalidCoordinate
434 || other.type() == QGeoCoordinate::InvalidCoordinate) {
438 double dlon = qDegreesToRadians(other.d->lng - d->lng);
439 double lat1Rad = qDegreesToRadians(d->lat);
440 double lat2Rad = qDegreesToRadians(other.d->lat);
442 double y = sin(dlon) * cos(lat2Rad);
443 double x = cos(lat1Rad) * sin(lat2Rad) - sin(lat1Rad) * cos(lat2Rad) * cos(dlon);
445 double azimuth = qRadiansToDegrees(atan2(y, x)) + 360.0;
447 double fraction = modf(azimuth, &whole);
448 return qreal((
int(whole + 360) % 360) + fraction);
451void QGeoCoordinatePrivate::atDistanceAndAzimuth(
const QGeoCoordinate &coord,
452 qreal distance, qreal azimuth,
453 double *lon,
double *lat)
455 double latRad = qDegreesToRadians(coord.d->lat);
456 double lonRad = qDegreesToRadians(coord.d->lng);
457 double cosLatRad = cos(latRad);
458 double sinLatRad = sin(latRad);
460 double azimuthRad = qDegreesToRadians(azimuth);
462 double ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0));
463 double cosRatio = cos(ratio);
464 double sinRatio = sin(ratio);
466 double resultLatRad = asin(sinLatRad * cosRatio
467 + cosLatRad * sinRatio * cos(azimuthRad));
468 double resultLonRad = lonRad + atan2(sin(azimuthRad) * sinRatio * cosLatRad,
469 cosRatio - sinLatRad * sin(resultLatRad));
471 *lat = qRadiansToDegrees(resultLatRad);
472 *lon = qRadiansToDegrees(resultLonRad);
476
477
478
479
480
481
482
483
484
485QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp)
const
488 return QGeoCoordinate();
490 double resultLon, resultLat;
491 QGeoCoordinatePrivate::atDistanceAndAzimuth(*
this, distance, azimuth,
492 &resultLon, &resultLat);
493 double resultAlt = d->alt + distanceUp;
494 return QGeoCoordinate(resultLat, QLocationUtils::wrapLong(resultLon), resultAlt);
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532QString QGeoCoordinate::toString(CoordinateFormat format)
const
534 if (type() == QGeoCoordinate::InvalidCoordinate)
540 double absLat = qAbs(d->lat);
541 double absLng = qAbs(d->lng);
542 QChar symbol(0x00B0);
546 case DegreesWithHemisphere: {
547 latStr = QString::number(absLat,
'f', 5) + symbol;
548 longStr = QString::number(absLng,
'f', 5) + symbol;
552 case DegreesMinutesWithHemisphere: {
553 double latMin = (absLat -
int(absLat)) * 60;
554 double lngMin = (absLng -
int(absLng)) * 60;
561 if (latMin > 59.9995) {
565 if (lngMin > 59.9995) {
570 latStr = QString::fromLatin1(
"%1%2 %3'")
571 .arg(QString::number(
int(absLat)))
573 .arg(QString::number(latMin,
'f', 3));
574 longStr = QString::fromLatin1(
"%1%2 %3'")
575 .arg(QString::number(
int(absLng)))
577 .arg(QString::number(lngMin,
'f', 3));
580 case DegreesMinutesSeconds:
581 case DegreesMinutesSecondsWithHemisphere: {
582 double latMin = (absLat -
int(absLat)) * 60;
583 double lngMin = (absLng -
int(absLng)) * 60;
584 double latSec = (latMin -
int(latMin)) * 60;
585 double lngSec = (lngMin -
int(lngMin)) * 60;
592 if (latSec >= 59.95) {
598 if (qRound(latMin) >= 60) {
603 if (lngSec >= 59.95) {
606 if (qRound(lngMin) >= 60) {
612 latStr = QString::fromLatin1(
"%1%2 %3' %4\"")
613 .arg(QString::number(
int(absLat)))
615 .arg(QString::number(
int(latMin)))
616 .arg(QString::number(latSec,
'f', 1));
617 longStr = QString::fromLatin1(
"%1%2 %3' %4\"")
618 .arg(QString::number(
int(absLng)))
620 .arg(QString::number(
int(lngMin)))
621 .arg(QString::number(lngSec,
'f', 1));
630 case DegreesMinutesSeconds: {
632 latStr.insert(0, QStringLiteral(
"-"));
634 longStr.insert(0, QStringLiteral(
"-"));
637 case DegreesWithHemisphere:
638 case DegreesMinutesWithHemisphere:
639 case DegreesMinutesSecondsWithHemisphere: {
641 latStr.append(QString::fromLatin1(
" S"));
643 latStr.append(QString::fromLatin1(
" N"));
645 longStr.append(QString::fromLatin1(
" W"));
647 longStr.append(QString::fromLatin1(
" E"));
653 return QString::fromLatin1(
"%1, %2").arg(latStr, longStr);
654 return QString::fromLatin1(
"%1, %2, %3m").arg(latStr, longStr, QString::number(d->alt));
657bool QGeoCoordinate::equals(
const QGeoCoordinate &lhs,
const QGeoCoordinate &rhs)
659 bool latEqual = (qIsNaN(lhs.d->lat) && qIsNaN(rhs.d->lat))
660 || qFuzzyCompare(lhs.d->lat, rhs.d->lat);
661 bool lngEqual = (qIsNaN(lhs.d->lng) && qIsNaN(rhs.d->lng))
662 || qFuzzyCompare(lhs.d->lng, rhs.d->lng);
663 bool altEqual = (qIsNaN(lhs.d->alt) && qIsNaN(rhs.d->alt))
664 || qFuzzyCompare(lhs.d->alt, rhs.d->alt);
666 if (!qIsNaN(lhs.d->lat) && ((lhs.d->lat == 90.0) || (lhs.d->lat == -90.0)))
669 return (latEqual && lngEqual && altEqual);
672QGeoCoordinate::QGeoCoordinate(QGeoCoordinatePrivate &dd):
677#ifndef QT_NO_DEBUG_STREAM
678QDebug QGeoCoordinate::debugStreaming(QDebug dbg,
const QGeoCoordinate &coord)
680 QDebugStateSaver saver(dbg);
681 double lat = coord.latitude();
682 double lng = coord.longitude();
684 QTextStreamManipulator tsm = qSetRealNumberPrecision(11);
686 dbg.nospace() <<
"QGeoCoordinate(";
696 if (coord.type() == QGeoCoordinate::Coordinate3D) {
698 dbg << coord.altitude();
705#ifndef QT_NO_DATASTREAM
707
708
709
710
711
712
714QDataStream &QGeoCoordinate::dataStreamOut(QDataStream &stream,
const QGeoCoordinate &coordinate)
716 stream << coordinate.latitude();
717 stream << coordinate.longitude();
718 stream << coordinate.altitude();
723#ifndef QT_NO_DATASTREAM
725
726
727
728
729
730
731
733QDataStream &QGeoCoordinate::dataStreamIn(QDataStream &stream, QGeoCoordinate &coordinate)
737 coordinate.setLatitude(value);
739 coordinate.setLongitude(value);
741 coordinate.setAltitude(value);
747
748
749
750
753 QtPrivate::QHashCombine hash(seed);
755 if (coordinate.latitude() != 90.0 && coordinate.latitude() != -90.0)
756 seed = hash(seed, coordinate.longitude());
757 seed = hash(seed, coordinate.latitude());
758 seed = hash(seed, coordinate.altitude());
764#include "moc_qgeocoordinate.cpp"
Combined button and popup list for selecting options.
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept