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
78
81
82
83
84
85
86
87
90
91
92
93
94
95
96
97
98
99
100
101
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
140
141
142
143
144
145
146
147
148
149
152
153
154
155
156
157
158
159
160
161
162
165
166
167
168QGeoCoordinate::QGeoCoordinate()
169 : d(
new QGeoCoordinatePrivate)
174
175
176
177
178
179
180
181
182QGeoCoordinate::QGeoCoordinate(
double latitude,
double longitude)
183 : d(
new QGeoCoordinatePrivate)
185 if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
192
193
194
195
196
197
198
199
200
201
202
203QGeoCoordinate::QGeoCoordinate(
double latitude,
double longitude,
double altitude)
204 : d(
new QGeoCoordinatePrivate)
206 if (QLocationUtils::isValidLat(latitude) && QLocationUtils::isValidLong(longitude)) {
214
215
216QGeoCoordinate::QGeoCoordinate(
const QGeoCoordinate &other)
221
222
223
224
225
226
227
228
229
232
233
234QGeoCoordinate &QGeoCoordinate::operator=(
const QGeoCoordinate &other)
244
245
246
247
248
249
250
251
252
253
256
257
258QGeoCoordinate::~QGeoCoordinate()
262QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoCoordinatePrivate)
265
266
267
268
269
270
271
272
275
276
277
278
279
280
283
284
285
286
289
290
291bool QGeoCoordinate::isValid()
const
293 CoordinateType t = type();
294 return t == Coordinate2D || t == Coordinate3D;
298
299
300QGeoCoordinate::CoordinateType QGeoCoordinate::type()
const
302 if (QLocationUtils::isValidLat(d->lat)
303 && QLocationUtils::isValidLong(d->lng)) {
308 return InvalidCoordinate;
313
314
315
316
317
318
319
320
321double QGeoCoordinate::latitude()
const
327
328
329
330
331
332
333
334void QGeoCoordinate::setLatitude(
double latitude)
340
341
342
343
344
345
346
347
348double QGeoCoordinate::longitude()
const
354
355
356
357
358
359
360
361void QGeoCoordinate::setLongitude(
double longitude)
367
368
369
370
371
372
373double QGeoCoordinate::altitude()
const
379
380
381
382
383void QGeoCoordinate::setAltitude(
double altitude)
389
390
391
392
393
394
395
396
397
398
399qreal QGeoCoordinate::distanceTo(
const QGeoCoordinate &other)
const
401 if (type() == QGeoCoordinate::InvalidCoordinate
402 || other.type() == QGeoCoordinate::InvalidCoordinate) {
407 double dlat = qDegreesToRadians(other.d->lat - d->lat);
408 double dlon = qDegreesToRadians(other.d->lng - d->lng);
409 double haversine_dlat = sin(dlat / 2.0);
410 haversine_dlat *= haversine_dlat;
411 double haversine_dlon = sin(dlon / 2.0);
412 haversine_dlon *= haversine_dlon;
413 double y = haversine_dlat
414 + cos(qDegreesToRadians(d->lat))
415 * cos(qDegreesToRadians(other.d->lat))
417 double x = 2 * asin(sqrt(y));
418 return qreal(x * qgeocoordinate_EARTH_MEAN_RADIUS * 1000);
422
423
424
425
426
427
428
429
430
431
432qreal QGeoCoordinate::azimuthTo(
const QGeoCoordinate &other)
const
434 if (type() == QGeoCoordinate::InvalidCoordinate
435 || other.type() == QGeoCoordinate::InvalidCoordinate) {
439 double dlon = qDegreesToRadians(other.d->lng - d->lng);
440 double lat1Rad = qDegreesToRadians(d->lat);
441 double lat2Rad = qDegreesToRadians(other.d->lat);
443 double y = sin(dlon) * cos(lat2Rad);
444 double x = cos(lat1Rad) * sin(lat2Rad) - sin(lat1Rad) * cos(lat2Rad) * cos(dlon);
446 double azimuth = qRadiansToDegrees(atan2(y, x)) + 360.0;
448 double fraction = modf(azimuth, &whole);
449 return qreal((
int(whole + 360) % 360) + fraction);
452void QGeoCoordinatePrivate::atDistanceAndAzimuth(
const QGeoCoordinate &coord,
453 qreal distance, qreal azimuth,
454 double *lon,
double *lat)
456 double latRad = qDegreesToRadians(coord.d->lat);
457 double lonRad = qDegreesToRadians(coord.d->lng);
458 double cosLatRad = cos(latRad);
459 double sinLatRad = sin(latRad);
461 double azimuthRad = qDegreesToRadians(azimuth);
463 double ratio = (distance / (qgeocoordinate_EARTH_MEAN_RADIUS * 1000.0));
464 double cosRatio = cos(ratio);
465 double sinRatio = sin(ratio);
467 double resultLatRad = asin(sinLatRad * cosRatio
468 + cosLatRad * sinRatio * cos(azimuthRad));
469 double resultLonRad = lonRad + atan2(sin(azimuthRad) * sinRatio * cosLatRad,
470 cosRatio - sinLatRad * sin(resultLatRad));
472 *lat = qRadiansToDegrees(resultLatRad);
473 *lon = qRadiansToDegrees(resultLonRad);
477
478
479
480
481
482
483
484
485
486QGeoCoordinate QGeoCoordinate::atDistanceAndAzimuth(qreal distance, qreal azimuth, qreal distanceUp)
const
489 return QGeoCoordinate();
491 double resultLon, resultLat;
492 QGeoCoordinatePrivate::atDistanceAndAzimuth(*
this, distance, azimuth,
493 &resultLon, &resultLat);
494 double resultAlt = d->alt + distanceUp;
495 return QGeoCoordinate(resultLat, QLocationUtils::wrapLong(resultLon), resultAlt);
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
532
533QString QGeoCoordinate::toString(CoordinateFormat format)
const
535 if (type() == QGeoCoordinate::InvalidCoordinate)
541 double absLat = qAbs(d->lat);
542 double absLng = qAbs(d->lng);
543 QChar symbol(0x00B0);
547 case DegreesWithHemisphere: {
548 latStr = QString::number(absLat,
'f', 5) + symbol;
549 longStr = QString::number(absLng,
'f', 5) + symbol;
553 case DegreesMinutesWithHemisphere: {
554 double latMin = (absLat -
int(absLat)) * 60;
555 double lngMin = (absLng -
int(absLng)) * 60;
562 if (latMin > 59.9995) {
566 if (lngMin > 59.9995) {
571 latStr = QString::fromLatin1(
"%1%2 %3'")
572 .arg(QString::number(
int(absLat)))
574 .arg(QString::number(latMin,
'f', 3));
575 longStr = QString::fromLatin1(
"%1%2 %3'")
576 .arg(QString::number(
int(absLng)))
578 .arg(QString::number(lngMin,
'f', 3));
581 case DegreesMinutesSeconds:
582 case DegreesMinutesSecondsWithHemisphere: {
583 double latMin = (absLat -
int(absLat)) * 60;
584 double lngMin = (absLng -
int(absLng)) * 60;
585 double latSec = (latMin -
int(latMin)) * 60;
586 double lngSec = (lngMin -
int(lngMin)) * 60;
593 if (latSec >= 59.95) {
599 if (qRound(latMin) >= 60) {
604 if (lngSec >= 59.95) {
607 if (qRound(lngMin) >= 60) {
613 latStr = QString::fromLatin1(
"%1%2 %3' %4\"")
614 .arg(QString::number(
int(absLat)))
616 .arg(QString::number(
int(latMin)))
617 .arg(QString::number(latSec,
'f', 1));
618 longStr = QString::fromLatin1(
"%1%2 %3' %4\"")
619 .arg(QString::number(
int(absLng)))
621 .arg(QString::number(
int(lngMin)))
622 .arg(QString::number(lngSec,
'f', 1));
631 case DegreesMinutesSeconds: {
633 latStr.insert(0, QStringLiteral(
"-"));
635 longStr.insert(0, QStringLiteral(
"-"));
638 case DegreesWithHemisphere:
639 case DegreesMinutesWithHemisphere:
640 case DegreesMinutesSecondsWithHemisphere: {
642 latStr.append(QString::fromLatin1(
" S"));
644 latStr.append(QString::fromLatin1(
" N"));
646 longStr.append(QString::fromLatin1(
" W"));
648 longStr.append(QString::fromLatin1(
" E"));
654 return QString::fromLatin1(
"%1, %2").arg(latStr, longStr);
655 return QString::fromLatin1(
"%1, %2, %3m").arg(latStr, longStr, QString::number(d->alt));
658bool QGeoCoordinate::equals(
const QGeoCoordinate &lhs,
const QGeoCoordinate &rhs)
660 bool latEqual = (qIsNaN(lhs.d->lat) && qIsNaN(rhs.d->lat))
661 || qFuzzyCompare(lhs.d->lat, rhs.d->lat);
662 bool lngEqual = (qIsNaN(lhs.d->lng) && qIsNaN(rhs.d->lng))
663 || qFuzzyCompare(lhs.d->lng, rhs.d->lng);
664 bool altEqual = (qIsNaN(lhs.d->alt) && qIsNaN(rhs.d->alt))
665 || qFuzzyCompare(lhs.d->alt, rhs.d->alt);
667 if (!qIsNaN(lhs.d->lat) && ((lhs.d->lat == 90.0) || (lhs.d->lat == -90.0)))
670 return (latEqual && lngEqual && altEqual);
673QGeoCoordinate::QGeoCoordinate(QGeoCoordinatePrivate &dd):
678#ifndef QT_NO_DEBUG_STREAM
679QDebug QGeoCoordinate::debugStreaming(QDebug dbg,
const QGeoCoordinate &coord)
681 QDebugStateSaver saver(dbg);
682 double lat = coord.latitude();
683 double lng = coord.longitude();
685 QTextStreamManipulator tsm = qSetRealNumberPrecision(11);
687 dbg.nospace() <<
"QGeoCoordinate(";
697 if (coord.type() == QGeoCoordinate::Coordinate3D) {
699 dbg << coord.altitude();
706#ifndef QT_NO_DATASTREAM
708
709
710
711
712
713
715QDataStream &QGeoCoordinate::dataStreamOut(QDataStream &stream,
const QGeoCoordinate &coordinate)
717 stream << coordinate.latitude();
718 stream << coordinate.longitude();
719 stream << coordinate.altitude();
724#ifndef QT_NO_DATASTREAM
726
727
728
729
730
731
732
734QDataStream &QGeoCoordinate::dataStreamIn(QDataStream &stream, QGeoCoordinate &coordinate)
738 coordinate.setLatitude(value);
740 coordinate.setLongitude(value);
742 coordinate.setAltitude(value);
748
749
750
751
754 QtPrivate::QHashCombine hash;
756 if (coordinate.latitude() != 90.0 && coordinate.latitude() != -90.0)
757 seed = hash(seed, coordinate.longitude());
758 seed = hash(seed, coordinate.latitude());
759 seed = hash(seed, coordinate.altitude());
765#include "moc_qgeocoordinate.cpp"
Combined button and popup list for selecting options.
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept