void GpsLocation::newPosition(QGeoPositionInfo pos) { int64_t lastTime = 0; QGeoCoordinate lastCoord; int nr = m_trackers.count(); if (nr) { gpsTracker gt = m_trackers.last(); lastCoord.setLatitude(gt.latitude.udeg / 1000000.0); lastCoord.setLongitude(gt.longitude.udeg / 1000000.0); lastTime = gt.when; } // if we are waiting for a position update or // if we have no record stored or if at least the configured minimum // time has passed or we moved at least the configured minimum distance int64_t delta = (int64_t)pos.timestamp().toTime_t() + gettimezoneoffset() - lastTime; if (!nr || waitingForPosition || delta > prefs.time_threshold || lastCoord.distanceTo(pos.coordinate()) > prefs.distance_threshold) { QString msg("received new position %1 after delta %2 threshold %3 (now %4 last %5)"); status(qPrintable(msg.arg(pos.coordinate().toString()).arg(delta).arg(prefs.time_threshold).arg(pos.timestamp().toString()).arg(QDateTime().fromMSecsSinceEpoch(lastTime * 1000).toString()))); waitingForPosition = false; acquiredPosition(); gpsTracker gt; gt.when = pos.timestamp().toTime_t(); gt.when += gettimezoneoffset(gt.when); gt.latitude.udeg = lrint(pos.coordinate().latitude() * 1000000); gt.longitude.udeg = lrint(pos.coordinate().longitude() * 1000000); addFixToStorage(gt); gpsTracker gtNew = m_trackers.last(); qDebug() << "newest fix is now at" << QDateTime().fromMSecsSinceEpoch(gtNew.when - gettimezoneoffset(gtNew.when) * 1000).toString(); } }
void QTMLocationProvider::positionUpdated(const QGeoPositionInfo &geoPosition) { if (!geoPosition.isValid()) { NS_WARNING("Invalida geoposition received"); return; } QGeoCoordinate coord = geoPosition.coordinate(); double latitude = coord.latitude(); double longitude = coord.longitude(); double altitude = coord.altitude(); double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy); double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy); double heading = geoPosition.attribute(QGeoPositionInfo::Direction); bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed); double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed); nsRefPtr<nsGeoPosition> p = new nsGeoPosition(latitude, longitude, altitude, accuracy, altitudeAccuracy, heading, speed, geoPosition.timestamp().toTime_t()); if (mCallback) { mCallback->Update(p); } }
void GeolocationClientQt::positionUpdated(const QGeoPositionInfo &geoPosition) { if (!geoPosition.isValid()) return; QGeoCoordinate coord = geoPosition.coordinate(); double latitude = coord.latitude(); double longitude = coord.longitude(); bool providesAltitude = (geoPosition.coordinate().type() == QGeoCoordinate::Coordinate3D); double altitude = coord.altitude(); double accuracy = geoPosition.attribute(QGeoPositionInfo::HorizontalAccuracy); bool providesAltitudeAccuracy = geoPosition.hasAttribute(QGeoPositionInfo::VerticalAccuracy); double altitudeAccuracy = geoPosition.attribute(QGeoPositionInfo::VerticalAccuracy); bool providesHeading = geoPosition.hasAttribute(QGeoPositionInfo::Direction); double heading = geoPosition.attribute(QGeoPositionInfo::Direction); bool providesSpeed = geoPosition.hasAttribute(QGeoPositionInfo::GroundSpeed); double speed = geoPosition.attribute(QGeoPositionInfo::GroundSpeed); double timeStampInSeconds = geoPosition.timestamp().toMSecsSinceEpoch() / 1000; m_lastPosition = GeolocationPosition::create(timeStampInSeconds, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); WebCore::Page* page = QWebPagePrivate::core(m_page); page->geolocationController()->positionChanged(m_lastPosition.get()); }
void KTracks::on_acSelect_triggered() { QModelIndexList selection = ui->tvTracks->selectionModel()->selectedRows(); QAbstractItemModel *model = ui->tvTracks->model(); if (!selection.isEmpty()) { QList<QGeoPositionInfo> trackList; trackList.clear(); trackList = sql.selTrack(model->data(model->index(selection.at(0).row(),0)).toInt()); ui->cpPlot->clearGraphs(); ui->cpPlot->addGraph(); QGeoPositionInfo tp; QVector<double> x; QVector<double> y; int cnt = trackList.count(); x.resize(cnt); y.resize(cnt); //options int pType; if (ui->miAltitude->isChecked()) { ui->cpPlot->yAxis->setLabel("Altitude [m]"); pType = 1; } if (ui->miDistance->isChecked()) { ui->cpPlot->yAxis->setLabel("Distance [m]"); pType = 2; } if (ui->miSpeed->isChecked()) { ui->cpPlot->yAxis->setLabel("Speed [m/s]"); pType = 3; } ui->cpPlot->xAxis->setLabel("time [hh:mm:ss]"); for (int i=0; i<cnt; i++) { tp = trackList.value(i); x[i] = tp.timestamp().toTime_t(); switch (pType) { case 1: { y[i] = tp.coordinate().altitude(); break; } case 2: { y[i] = tp.coordinate().distanceTo(trackList.value(0).coordinate()); break; } case 3: { y[i] = tp.attribute(QGeoPositionInfo::GroundSpeed); break; } } //switch } //for to ui->cpPlot->graph(0)->setData(x,y); // set axes ranges, so we see all data: ui->cpPlot->xAxis->setRange(x[0],x[cnt-1]); qSort(y.begin(), y.end()); ui->cpPlot->yAxis->setRange(y.first(),y.last()); //repaint ui->cpPlot->replot(); } //selection.isempty }
void QGeoPositionInfoSourceAndroid::requestTimeout() { AndroidPositioning::stopUpdates(androidClassKeyForSingleRequest); //no queued update to process -> timeout const int count = queuedSingleUpdates.count(); if (!count) { emit updateTimeout(); return; } //pick best QGeoPositionInfo best = queuedSingleUpdates[0]; for (int i = 1; i < count; i++) { const QGeoPositionInfo info = queuedSingleUpdates[i]; //anything newer by 20s is always better const int timeDelta = best.timestamp().secsTo(info.timestamp()); if (abs(timeDelta) > 20) { if (timeDelta > 0) best = info; continue; } //compare accuracy if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy) && info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { best = info.attribute(QGeoPositionInfo::HorizontalAccuracy) < best.attribute(QGeoPositionInfo::HorizontalAccuracy) ? info : best; continue; } //prefer info with accuracy information if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) best = info; } queuedSingleUpdates.clear(); emit positionUpdated(best); }
void PushN8PhoneGPS::positionUpdated(QGeoPositionInfo info) { if(info.isValid() && !gpsOnline) { emit connected(); gpsOnline = true; qDebug() << "GPS now connected"; } // if(info.coordinate().isValid() && !gpsOnline) // { // //emitting connected signal when receiving first reading // emit connected(); // gpsOnline = true; // } else if(gpsOnline) { // gpsOnline = false; // emit disconnected(); // } if(!streaming) return; if(info.timestamp().isValid()) { //&& info.coordinate().isValid() QDateTime correctedTstamp; correctedTstamp = info.timestamp().addSecs(UTCOffset);//ugly localisation! info.setTimestamp(correctedTstamp); //double checking speed NPushGpsTick * newGPSTick = new NPushGpsTick(info); if(receivers(SIGNAL(reading_ready(NPushLogTick*))) > 0) { emit reading_ready(newGPSTick); } else { delete newGPSTick;
// Testcase to check that values are passed correctly void TestQGeoPositionInfoSource::updateValues() { CHECK_SOURCE_VALID; QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); m_source->startUpdates(); QTRY_VERIFY_WITH_TIMEOUT(!spy.isEmpty(), 2000); QList<QVariant> list = spy.takeFirst(); QGeoPositionInfo info; info = list.at(0).value<QGeoPositionInfo>(); QCOMPARE(qFuzzyCompare(info.coordinate().latitude(), 21), TRUE ); QCOMPARE(qFuzzyCompare(info.coordinate().longitude(), 31), TRUE ); QCOMPARE(qFuzzyCompare(info.coordinate().altitude(), 5.1), TRUE ); QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy), 8), TRUE ); QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy), 9), TRUE ); QDateTime dateTime; dateTime.setTime_t(99998); // there is some rounding difference impacting at sec level // hence don't compare directly QCOMPARE(info.timestamp().date(),dateTime.date()); QCOMPARE(info.timestamp().time().hour(),dateTime.time().hour()); }
void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &position) { /* Invalid fixes have NaN for horizontal accuracy regardless of whether they come from satellite or non-satellite position methods. Satellite fixes always have LOCATION_GPS_DEVICE_TIME_SET. If this is not set and we have a numeric value for horizontal accuracy then we are dealing with a non-satellite based positioning method. Since QGeoPositionInfo instances are only considered valid if they have a valid coordinate and a valid timestamp, we use the current date and time as the timestamp for the network based positioning. This will help in the case where someone wants to reply a journey from a log file. Based on some logging it looks like satellite and non-satellite methods can be distinguished (after the initial fix) by whether the time has been set and / or whether the horizontal accuracy is above or below around 500 metres. Using the timestamp appears to be more definitive than using the accuracy. */ const bool horizontalAccuracyDefined = !qIsNaN(position.attribute(QGeoPositionInfo::HorizontalAccuracy)); const bool hasTimeStamp = !position.timestamp().isNull(); if (horizontalAccuracyDefined) { if (hasTimeStamp) { //Valid satellite fix lastUpdateFromSatellite = position; } else { //Valid non-satellite fix QGeoPositionInfo networkPosition(position); networkPosition.setTimestamp(QDateTime::currentDateTime()); lastUpdateFromNetwork = networkPosition; } } else { //Invalid position update if (hasTimeStamp) { lastUpdateFromSatellite = QGeoPositionInfo(); } else { lastUpdateFromNetwork = QGeoPositionInfo(); } } }
void QNmeaSimulatedReader::processNextSentence() { QGeoPositionInfo info; bool hasFix = false; int timeToNextUpdate = -1; QTime prevTime; if (m_pendingUpdates.size() > 0) prevTime = m_pendingUpdates.head().info.timestamp().time(); // find the next update with a valid time (as long as the time is valid, // we can calculate when the update should be emitted) while (m_proxy->m_device && m_proxy->m_device->bytesAvailable() > 0) { char buf[1024]; qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); if (size <= 0) continue; if (m_proxy->parsePosInfoFromNmeaData(buf, size, &info, &hasFix)) { QTime time = info.timestamp().time(); if (time.isValid()) { if (!prevTime.isValid()) { timeToNextUpdate = 0; break; } timeToNextUpdate = prevTime.msecsTo(time); if (timeToNextUpdate >= 0) break; } else { timeToNextUpdate = 0; break; } } } if (timeToNextUpdate < 0) return; m_pendingUpdates.dequeue(); QPendingGeoPositionInfo pending; pending.info = info; pending.hasFix = hasFix; m_pendingUpdates.enqueue(pending); m_currTimerId = startTimer(timeToNextUpdate); }
void tst_QNmeaPositionInfoSource::startUpdates_waitForValidDateTime() { // Tests that the class does not emit an update until it receives a // sentences with a valid date *and* time. All sentences before this // should be ignored, and any sentences received after this that do // not have a date should use the known date. QFETCH(QByteArray, bytes); QFETCH(QList<QDateTime>, dateTimes); QFETCH(QList<bool>, expectHorizontalAccuracy); QFETCH(QList<bool>, expectVerticalAccuracy); QNmeaPositionInfoSource source(m_mode); source.setUserEquivalentRangeError(5.1); QNmeaPositionInfoSourceProxyFactory factory; QNmeaPositionInfoSourceProxy *proxy = static_cast<QNmeaPositionInfoSourceProxy*>(factory.createProxy(&source)); QSignalSpy spy(proxy->source(), SIGNAL(positionUpdated(QGeoPositionInfo))); proxy->source()->startUpdates(); proxy->feedBytes(bytes); QTRY_COMPARE(spy.count(), dateTimes.count()); for (int i=0; i<spy.count(); i++) { QGeoPositionInfo pInfo = spy[i][0].value<QGeoPositionInfo>(); QCOMPARE(pInfo.timestamp(), dateTimes[i]); // Generated GGA/GSA sentences have hard coded HDOP of 3.5, which corrisponds to a // horizontal accuracy of 35.7, for the user equivalent range error of 5.1 set above. QCOMPARE(pInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy), expectHorizontalAccuracy[i]); if (pInfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) QVERIFY(qFuzzyCompare(pInfo.attribute(QGeoPositionInfo::HorizontalAccuracy), 35.7)); // Generate GSA sentences have hard coded VDOP of 4.0, which corrisponds to a vertical // accuracy of 40.8, for the user equivalent range error of 5.1 set above. QCOMPARE(pInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy), expectVerticalAccuracy[i]); if (pInfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) QVERIFY(qFuzzyCompare(pInfo.attribute(QGeoPositionInfo::VerticalAccuracy), 40.8)); } }
bool QNmeaSimulatedReader::setFirstDateTime() { // find the first update with valid date and time QGeoPositionInfo update; bool hasFix = false; while (m_proxy->m_device->bytesAvailable() > 0) { char buf[1024]; qint64 size = m_proxy->m_device->readLine(buf, sizeof(buf)); if (size <= 0) continue; bool ok = m_proxy->parsePosInfoFromNmeaData(buf, size, &update, &hasFix); if (ok && update.timestamp().isValid()) { QPendingGeoPositionInfo pending; pending.info = update; pending.hasFix = hasFix; m_pendingUpdates.enqueue(pending); return true; } } return false; }
int CLbsPositionLogger::Write(const QGeoPositionInfo &info) { int nRet = 0; QString szContext; szContext = QString::number(info.timestamp().toUTC().toTime_t()) + "," + QString::number(info.coordinate().latitude()) + "," + QString::number(info.coordinate().longitude()) + ","; if(!qIsNaN(info.coordinate().altitude())) szContext += QString::number(info.coordinate().altitude()); szContext += ","; if(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) szContext += QString::number(info.attribute(QGeoPositionInfo::HorizontalAccuracy)); szContext += ","; if(info.hasAttribute(QGeoPositionInfo::Direction)) szContext += QString::number(info.attribute(QGeoPositionInfo::Direction)); szContext += ","; if(info.hasAttribute(QGeoPositionInfo::GroundSpeed)) szContext += QString::number(info.attribute(QGeoPositionInfo::GroundSpeed)); szContext += "\n"; m_logFile.write(szContext.toStdString().c_str(), szContext.length()); return nRet; }
void JSKitGeolocation::handlePosition(const QGeoPositionInfo &pos) { qCDebug(l) << "got position at" << pos.timestamp() << "type" << pos.coordinate().type(); if (_watches.empty()) { qCWarning(l) << "got position update but no one is watching"; _source->stopUpdates(); // Just in case. return; } QJSValue obj = buildPositionObject(pos); for (auto it = _watches.begin(); it != _watches.end(); /*no adv*/) { invokeCallback(it->successCallback, obj); if (it->once) { it = _watches.erase(it); } else { it->timer.restart(); ++it; } } }
void ClientApplication::positionUpdated(const QGeoPositionInfo &info) { textEdit->append(QString("Position updated: Date/time = %1, Coordinate = %2").arg(info.timestamp().toString()).arg(info.coordinate().toString())); }
void TRMainWindow::newLocationInfoReceived(const QGeoPositionInfo positionInfo) { QGeoCoordinate currentCoords = positionInfo.coordinate(); if(m_lastKnownPosition || !(currentCoords == *m_lastKnownPosition)) { // We need to write to the file, let's initialize it if(m_outputKMLFile == NULL) { // File initialization QString timeStamp = positionInfo.timestamp().toString(Qt::ISODate); QString fileTimeStamp = positionInfo.timestamp().toString("hhmmssddMMyy"); m_outputKMLFile = new QFile("c://Data//trackroute_"+fileTimeStamp+".kml"); m_outputKMLFile->open(QIODevice::WriteOnly | QIODevice::Text); // File writer initialization if(m_kmlFileWriter == NULL) { // Header m_kmlFileWriter = new QXmlStreamWriter(m_outputKMLFile); m_kmlFileWriter->writeStartDocument(); m_kmlFileWriter->writeNamespace("http://www.opengis.net/kml/2.2","kml"); // Document m_kmlFileWriter->writeStartElement("Document"); m_kmlFileWriter->writeTextElement("name","TrackRoute Path File"); m_kmlFileWriter->writeTextElement("description","Pathfile generated by Trackroute on: "+timeStamp); // Style m_kmlFileWriter->writeStartElement("Style"); m_kmlFileWriter->writeAttribute("id","yellowLineGreenPoly"); // LineStyle m_kmlFileWriter->writeStartElement("LineStyle"); m_kmlFileWriter->writeTextElement("color","7f00ffff"); m_kmlFileWriter->writeTextElement("width","4"); m_kmlFileWriter->writeEndElement(); // PolyStyle m_kmlFileWriter->writeStartElement("PolyStyle"); m_kmlFileWriter->writeTextElement("color","7f00ff00"); m_kmlFileWriter->writeEndElement(); // End Style m_kmlFileWriter->writeEndElement(); // Placemark m_kmlFileWriter->writeStartElement("Placemark"); m_kmlFileWriter->writeTextElement("name","TrackRoute Path "+timeStamp); m_kmlFileWriter->writeTextElement("description","Path generated by Trackroute on: "+timeStamp); m_kmlFileWriter->writeTextElement("styleUrl","#yellowLineGreenPoly"); // LineString m_kmlFileWriter->writeStartElement("LineString"); m_kmlFileWriter->writeTextElement("extrude","1"); m_kmlFileWriter->writeTextElement("tessellate","1"); m_kmlFileWriter->writeTextElement("altitudeMode","absolute"); // Coordinates m_kmlFileWriter->writeStartElement("coordinates"); } } // Update data m_numberOfUpdatesReceived++; m_currentSpeed = positionInfo.attribute(QGeoPositionInfo::GroundSpeed); m_currentSpeed = m_currentSpeed > 0 ? m_currentSpeed:0; m_totalSpeed += m_currentSpeed; m_averageSpeed = m_totalSpeed / m_numberOfUpdatesReceived; QString coordString = currentCoords.toString(); // Update UI ui->latLonDataLabel->setText(coordString.left(coordString.lastIndexOf(","))); ui->altitudeDataLabel->setText(QString::number(currentCoords.altitude())+" m"); ui->wptNumberDataLabel->setText(QString::number(m_numberOfUpdatesReceived)); ui->currentSpdDataLabel->setText(QString::number(m_currentSpeed)+" km/h"); ui->averageSpdDataLabel->setText(QString::number(m_averageSpeed)+" km/h"); // Write to the KML file QString locationData = QString::number(currentCoords.latitude()).append(",").append(QString::number(currentCoords.longitude())) .append(",").append(QString::number(currentCoords.altitude())).append(" "); m_kmlFileWriter->writeCharacters(locationData); m_outputKMLFile->flush(); } m_lastKnownPosition = ¤tCoords; }
void QDeclarativePosition::setPosition(const QGeoPositionInfo &info) { // timestamp const QDateTime pTimestamp = m_info.timestamp(); const QDateTime timestamp = info.timestamp(); bool emitTimestampChanged = pTimestamp != timestamp; // coordinate const QGeoCoordinate pCoordinate = m_info.coordinate(); const QGeoCoordinate coordinate = info.coordinate(); bool emitCoordinateChanged = pCoordinate != coordinate; bool emitLatitudeValidChanged = exclusiveNaN(pCoordinate.latitude(), coordinate.latitude()); bool emitLongitudeValidChanged = exclusiveNaN(pCoordinate.longitude(), coordinate.longitude()); bool emitAltitudeValidChanged = exclusiveNaN(pCoordinate.altitude(), coordinate.altitude()); // direction const qreal pDirection = m_info.attribute(QGeoPositionInfo::Direction); const qreal direction = info.attribute(QGeoPositionInfo::Direction); bool emitDirectionChanged = !equalOrNaN(pDirection, direction); bool emitDirectionValidChanged = exclusiveNaN(pDirection, direction); // ground speed const qreal pSpeed = m_info.attribute(QGeoPositionInfo::GroundSpeed); const qreal speed = info.attribute(QGeoPositionInfo::GroundSpeed); bool emitSpeedChanged = !equalOrNaN(pSpeed, speed); bool emitSpeedValidChanged = exclusiveNaN(pSpeed, speed); // vertical speed const qreal pVerticalSpeed = m_info.attribute(QGeoPositionInfo::VerticalSpeed); const qreal verticalSpeed = info.attribute(QGeoPositionInfo::VerticalSpeed); bool emitVerticalSpeedChanged = !equalOrNaN(pVerticalSpeed, verticalSpeed); bool emitVerticalSpeedValidChanged = exclusiveNaN(pVerticalSpeed, verticalSpeed); // magnetic variation const qreal pMagneticVariation = m_info.attribute(QGeoPositionInfo::MagneticVariation); const qreal magneticVariation = info.attribute(QGeoPositionInfo::MagneticVariation); bool emitMagneticVariationChanged = !equalOrNaN(pMagneticVariation, magneticVariation); bool emitMagneticVariationValidChanged = exclusiveNaN(pMagneticVariation, magneticVariation); // horizontal accuracy const qreal pHorizontalAccuracy = m_info.attribute(QGeoPositionInfo::HorizontalAccuracy); const qreal horizontalAccuracy = info.attribute(QGeoPositionInfo::HorizontalAccuracy); bool emitHorizontalAccuracyChanged = !equalOrNaN(pHorizontalAccuracy, horizontalAccuracy); bool emitHorizontalAccuracyValidChanged = exclusiveNaN(pHorizontalAccuracy, horizontalAccuracy); // vertical accuracy const qreal pVerticalAccuracy = m_info.attribute(QGeoPositionInfo::VerticalAccuracy); const qreal verticalAccuracy = info.attribute(QGeoPositionInfo::VerticalAccuracy); bool emitVerticalAccuracyChanged = !equalOrNaN(pVerticalAccuracy, verticalAccuracy); bool emitVerticalAccuracyValidChanged = exclusiveNaN(pVerticalAccuracy, verticalAccuracy); m_info = info; if (emitTimestampChanged) emit timestampChanged(); if (emitCoordinateChanged) emit coordinateChanged(); if (emitLatitudeValidChanged) emit latitudeValidChanged(); if (emitLongitudeValidChanged) emit longitudeValidChanged(); if (emitAltitudeValidChanged) emit altitudeValidChanged(); if (emitDirectionChanged) emit directionChanged(); if (emitDirectionValidChanged) emit directionValidChanged(); if (emitSpeedChanged) emit speedChanged(); if (emitSpeedValidChanged) emit speedValidChanged(); if (emitVerticalSpeedChanged) emit verticalSpeedChanged(); if (emitVerticalSpeedValidChanged) emit verticalSpeedValidChanged(); if (emitHorizontalAccuracyChanged) emit horizontalAccuracyChanged(); if (emitHorizontalAccuracyValidChanged) emit horizontalAccuracyValidChanged(); if (emitVerticalAccuracyChanged) emit verticalAccuracyChanged(); if (emitVerticalAccuracyValidChanged) emit verticalAccuracyValidChanged(); if (emitMagneticVariationChanged) emit magneticVariationChanged(); if (emitMagneticVariationValidChanged) emit magneticVariationValidChanged(); }
void TestQGeoPositionInfoSource::lastKnownPosition() { CHECK_SOURCE_VALID; QFETCH(int, positioningMethod); QFETCH(bool, lastKnownPositionArgument); QFETCH(bool, positionValid); #if defined(Q_OS_SYMBIAN) QSKIP("Real GPS not suitable for autotesting, skipping the test.", SkipAll); #endif QGeoPositionInfoSource::PositioningMethods method = static_cast<QGeoPositionInfoSource::PositioningMethods>(positioningMethod); if ((m_source->supportedPositioningMethods() & method) == 0) QSKIP("Not a supported positioning method for this position source", SkipSingle); m_source->setPreferredPositioningMethods(method); QSignalSpy spy(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&))); QSignalSpy timeout(m_source, SIGNAL(updateTimeout())); int time_out = 7000; m_source->setUpdateInterval(time_out); m_source->startUpdates(); // Use QEventLoop instead of qWait() to ensure we stop as soon as a // position is emitted (otherwise the lastKnownPosition() may have // changed by the time it is checked) QEventLoop loop; QTimer timer; timer.setInterval(9500); connect(m_source, SIGNAL(positionUpdated(const QGeoPositionInfo&)), &loop, SLOT(quit())); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); timer.start(); loop.exec(); EXPECT_FAIL_WINCE_SEE_MOBILITY_337_ABORT; QVERIFY((spy.count() > 0) && (timeout.count() == 0)); QList<QVariant> list = spy.takeFirst(); QGeoPositionInfo info; info = list.at(0).value<QGeoPositionInfo>(); QGeoPositionInfo lastPositioninfo; lastPositioninfo = m_source->lastKnownPosition(lastKnownPositionArgument); QCOMPARE(lastPositioninfo.isValid(), positionValid); if (positionValid) { QCOMPARE(info.coordinate(), lastPositioninfo.coordinate()); QCOMPARE(info.timestamp(), lastPositioninfo.timestamp()); QCOMPARE(info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy), lastPositioninfo.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)); if (info.hasAttribute(QGeoPositionInfo::HorizontalAccuracy)) { bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::HorizontalAccuracy)); bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)); QCOMPARE(isNaN1, isNaN2); if (!isNaN1) { QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::HorizontalAccuracy), lastPositioninfo.attribute(QGeoPositionInfo::HorizontalAccuracy)), TRUE); } } QCOMPARE(info.hasAttribute(QGeoPositionInfo::VerticalAccuracy), lastPositioninfo.hasAttribute(QGeoPositionInfo::VerticalAccuracy)); if (info.hasAttribute(QGeoPositionInfo::VerticalAccuracy)) { bool isNaN1 = qIsNaN(info.attribute(QGeoPositionInfo::VerticalAccuracy)); bool isNaN2 = qIsNaN(lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)); QCOMPARE(isNaN1, isNaN2); if (!isNaN1) { QCOMPARE(qFuzzyCompare(info.attribute(QGeoPositionInfo::VerticalAccuracy), lastPositioninfo.attribute(QGeoPositionInfo::VerticalAccuracy)), TRUE); } } } m_source->stopUpdates(); }