コード例 #1
0
void QGeoPositionInfoSourceAndroid::updateTimeoutElapsed()
{
    QGeoPositionInfo position;
    position=m_lastUpdate;

    if (position.isValid())
    {
        if (m_positionInfoState & QGeoPositionInfoSourceAndroid::RequestActive)
        {
            m_requestTimer->stop();
            m_positionInfoState &= ~QGeoPositionInfoSourceAndroid::RequestActive;

            if (m_positionInfoState & QGeoPositionInfoSourceAndroid::Stopped
                ||!(m_positionInfoState & QGeoPositionInfoSourceAndroid::StartUpdateActive))
            {
                QtLocationJni::disableUpdates(this);
            }

        }
        emit positionUpdated(position);
    }
    else
    {
        emit updateTimeout();
    }
    activateTimer();
}
コード例 #2
0
ファイル: mainwindow.cpp プロジェクト: kolphi/QWeather
void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
    if (geoPositionInfo.isValid())
    {
        // Stop regular position updates, because a valid position has been
        // obtained
        locationDataSource->stopUpdates();

        // Get the current location as latitude and longitude
        QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
        qreal latitude = geoCoordinate.latitude();
        qreal longitude = geoCoordinate.longitude();



        QString string1;
        QString string2;
     //   QChar c = 'g';

        //build the string for latitude-longitude
        string1.setNum(latitude);
        this->latlng.append(string1);
        string2.setNum(longitude);
        this->latlng.append(",");
        this->latlng.append(string2);


        //send the location request
        sendRequest();
    }
}
コード例 #3
0
ファイル: ktracks.cpp プロジェクト: HeikoTietze/KTracks
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
}
コード例 #4
0
ファイル: LocationTracker.cpp プロジェクト: pabrou/bb-pro
void LocationTracker::positionUpdated(const QGeoPositionInfo& pos)
{

	m_latitude = pos.coordinate().latitude();
	m_longitude = pos.coordinate().longitude();

	emit dataChanged(pos);
}
コード例 #5
0
void FoursquareVenueSelectionPage::positionUpdated(const QGeoPositionInfo &update)
{
	mDebug(__func__) 
		<< "Position lookup done, we're at "
		<< update.coordinate().latitude() << "," 
		<< update.coordinate().longitude() << ". ";
	m_geoinfo = update;
	m_here->setEnabled(true);
}
コード例 #6
0
ファイル: gpstracker.cpp プロジェクト: idaohang/GPS-Tracker
void GPSTracker::positionUpdated(QGeoPositionInfo position) {
    if(tracking){
        addPosition(position);
    }
    emit positionUpdated(Point(position));
    horizontalAccuracy = position.attribute(QGeoPositionInfo::HorizontalAccuracy);
    verticalAccuracy   = position.attribute(QGeoPositionInfo::VerticalAccuracy);
    changeGPSStatus(RECEIVE);
}
コード例 #7
0
ファイル: gpslocation.cpp プロジェクト: nikobockerman/AtoBe
void GpsLocation::updateLocation(QGeoPositionInfo positionInfo)
{
    this->latitude = positionInfo.coordinate().latitude();
    this->longitude = positionInfo.coordinate().longitude();

    this->calculateXY();

    this->m_valid = true;

    emit(this->gpsLocationChanged(this));
}
コード例 #8
0
ファイル: routemepositioninfo.cpp プロジェクト: INdT/routeme
void RouteMePositionInfo::onPositionUpdated(const QGeoPositionInfo &info)
{
    if (!info.isValid() || !info.coordinate().isValid())
        return;

    QGeoCoordinate coordinate = info.coordinate();
    m_currentCoordinate.setGeoCoordinate(coordinate);

    emit currentCoordinateAvailable();

    stopUpdates();
}
コード例 #9
0
ファイル: locationwatcher.cpp プロジェクト: qwazix/oobProfile
void LocationWatcher::positionUpdated(const QGeoPositionInfo &info)
{
    if (info.isValid()) {

        double latitude=info.coordinate().latitude();
        double longitude=info.coordinate().longitude();

        //QSqlDatabase db = openDB();
        profilemanager pm;
        // QSqlDatabase db = QSqlDatabase::database("/home/user/.local/share/data/QML/OfflineStorage/Databases/3e6ed8d4e46837c47b903b1e4ae85712.sqlite");

      if( !db.open() )
      {
        qFatal( "Failed to connect." );
      }
      if( db.open() )
      {      
          QSqlQuery query(db);
          double radius = getSetting("radius").toDouble();

          QString HereProfile="";
          //start looping through all areas
          query.exec("SELECT * FROM records");
          while(query.next()) {
              QString lat = query.value(0).toString();
              QString lon = query.value(1).toString();
              QString profile = query.value(2).toString();
              double lat1 = lat.toDouble();
              double lon1 = lon.toDouble();
              double distance=cut(lat1,lon1,latitude,longitude);
              if(distance<radius){
                    qDebug() << "to vrikame: " << lat<<lon<<profile<<distance<<radius;
                    HereProfile=profile;
                    break;
              }else{
                  HereProfile="";
              }
          }//telos loop perioxes
          if(HereProfile!="")
              pm.setProfile(HereProfile);
          else {
              query.exec("SELECT value FROM settings WHERE key='previousProfile'");
              query.first();
              QString previous=query.value(0).toString();
              qDebug()<<previous;
              pm.setProfile(previous);
          }
      }
    }//telos isvalid

}
コード例 #10
0
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);
    }
}
コード例 #11
0
void
MapWidget::positionUpdated(const QGeoPositionInfo & info)
{
    follow->show();
    coord = QPointF(info.coordinate().latitude(), info.coordinate().longitude());
    positionMarker->setVisible(true);
    positionMarker->setCoordinate(QPointF(coord.y(), coord.x()));

    if (!follow->isChecked())
        return ;

    if (plugin && plugin->rect().contains(coord))
        centerView(coord, 17);
}
コード例 #12
0
void tst_PositionPlugin::getUpdates()
{
    QGeoPositionInfoSource *src = QGeoPositionInfoSource::createSource("test.source", 0);
    src->setUpdateInterval(1000);

    QSignalSpy spy(src, SIGNAL(positionUpdated(QGeoPositionInfo)));
    src->startUpdates();
    QTest::qWait(1500);
    QCOMPARE(spy.count(), 1);
    QCOMPARE(spy[0].size(), 1);

    QGeoPositionInfo info = qvariant_cast<QGeoPositionInfo>(spy[0][0]);
    QCOMPARE(info.coordinate().latitude(), 0.1);
    QCOMPARE(info.coordinate().longitude(), 0.1);
}
コード例 #13
0
ファイル: appmodel.cpp プロジェクト: lollinus/qt-5.3-examples
//! [3]
void AppModel::positionUpdated(QGeoPositionInfo gpsPos)
{
    d->coord = gpsPos.coordinate();

    if (!(d->useGps))
        return;

    QString latitude, longitude;
    longitude.setNum(d->coord.longitude());
    latitude.setNum(d->coord.latitude());
//! [3]

    //don't update more often then once a minute
    //to keep load on server low
    if (d->throttle.isValid() && d->throttle.elapsed() < 1000*10 ) {
        return;
    }
    d->throttle.restart();

    QUrl url("http://api.openweathermap.org/data/2.5/weather");
    QUrlQuery query;
    query.addQueryItem("lat", latitude);
    query.addQueryItem("lon", longitude);
    query.addQueryItem("mode", "json");
    url.setQuery(query);

    QNetworkReply *rep = d->nam->get(QNetworkRequest(url));
    // connect up the signal right away
    d->geoReplyMapper->setMapping(rep, rep);
    connect(rep, SIGNAL(finished()),
            d->geoReplyMapper, SLOT(map()));
}
コード例 #14
0
ファイル: appmodel.cpp プロジェクト: amccarthy/qtlocation
//! [3]
void AppModel::positionUpdated(QGeoPositionInfo gpsPos)
{
    d->coord = gpsPos.coordinate();

    if (!(d->useGps))
        return;

    QString latitude, longitude;
    longitude.setNum(d->coord.longitude());
    latitude.setNum(d->coord.latitude());
//! [3]
    QUrl url("http://maps.google.com/maps/geo");
    QUrlQuery query;
    query.addQueryItem("q", latitude + "," + longitude);
    query.addQueryItem("output", "xml");
    url.setQuery(query);

    QNetworkReply *rep = d->nam->get(QNetworkRequest(url));
    // connect up the signal right away
    d->geoReplyMapper->setMapping(rep, rep);
    connect(rep, SIGNAL(finished()),
            d->geoReplyMapper, SLOT(map()));
    // it might have finished though while we were connecting it
    // if so, pass it straight on
    if (rep->isFinished())
        this->handleGeoNetworkData(rep);
}
コード例 #15
0
ファイル: TrackingService.cpp プロジェクト: OSLL/geo2tag-web
void TrackingService::sendMark()
{
    qDebug() << "sendMark";
    QGeoPositionInfo info = m_locationManager->getInfo();
    if (info.isValid())
    {
        m_dataMark->setLatitude(info.coordinate().latitude());
        m_dataMark->setLongitude(info.coordinate().longitude());
        m_dataMark->setTime();
        m_writeTagQuery->doRequest();
    }
    else
    {
        qDebug() << "invalid geo info, waitin and trying again";
        QTimer::singleShot(m_period * 1000, this, SLOT(sendMark()));
    }
}
コード例 #16
0
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();
        }
    }
}
コード例 #17
0
ファイル: appmodel.cpp プロジェクト: MarianMMX/MarianMMX
//! [3]
void AppModel::positionUpdated(QGeoPositionInfo gpsPos)
{
    d->coord = gpsPos.coordinate();

    if (!(d->useGps))
        return;

    queryCity();
}
コード例 #18
0
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);
}
コード例 #19
0
ファイル: gpswidget.cpp プロジェクト: Hrehory/EnigameQt
void GPSWidget::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
    //qWarning("positionUpdated");
    if (geoPositionInfo.isValid())
    {
        // Stop regular position updates, because a valid position has been
        // obtained
        locationDataSource->stopUpdates();

        // Get the current location as latitude and longitude
        geoCoordinate_ = geoPositionInfo.coordinate();


        emit gpsData(geoCoordinate_);

        locationDataSource->startUpdates();// chamówa

    }
}
コード例 #20
0
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;
}
コード例 #21
0
ファイル: gpslocation.cpp プロジェクト: torvalds/subsurface
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();
	}
}
コード例 #22
0
ファイル: gpxfile.cpp プロジェクト: HeikoTietze/KTracks
QList<QGeoPositionInfo> gpxfile::loadFrom(const QString fileName) {

  QFile file(fileName);
  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
      qDebug() << "File open error:" << file.errorString();
//      return false;
  }
  QXmlStreamReader xml(&file);

  QList<QGeoPositionInfo> trackList;
  trackList.clear();

  QGeoPositionInfo tp;
  QGeoCoordinate coord;
  QDateTime ts;

  while (!xml.atEnd() && !xml.hasError())
  {
      xml.readNext();

      if (xml.isStartElement()) {
          if (xml.name() == "trkpt") {
              coord.setLongitude(xml.attributes().value("lon").toFloat());
              coord.setLatitude(xml.attributes().value("lat").toFloat());
              while (xml.readNextStartElement()) {
                if (xml.name() == "ele")
                   coord.setAltitude(xml.readElementText().toFloat());
                else if (xml.name() == "time")
                   ts = QDateTime::fromString(xml.readElementText(),"yyyy-MM-dd'T'hh:mm:ss'Z'");
              } //ele, time
              tp.setCoordinate(coord);
              tp.setTimestamp(ts);
              trackList.append(tp);
          } //trkpt
      } //content

  } //eof

  return(trackList);
}
コード例 #23
0
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;
コード例 #24
0
void CLbsPositionLogger::readNextPosition()
{
    QByteArray line = m_logFile.readLine().trimmed();
    if (line.isEmpty()) {
        LOG_MODEL_ERROR("CLbsPositionLogger", "no readlien");
        return;
    }
    
    QList<QByteArray> data = line.split(',');
    
    QGeoCoordinate coordinate;
    QGeoPositionInfo info;
    
    bool hasTimestamp = false;
    QDateTime timestamp = QDateTime::fromTime_t(data.value(0).toLong(&hasTimestamp), Qt::UTC);
    if(hasTimestamp && timestamp.isValid())
        info.setTimestamp(timestamp);
    double latitude;
    bool hasLatitude = false;
    latitude = data.value(1).toDouble(&hasLatitude);
    if(hasLatitude)
        coordinate.setLatitude(latitude);
    double longitude;
    bool hasLongitude = false;
    longitude = data.value(2).toDouble(&hasLongitude);
    if(hasLongitude)
        coordinate.setLongitude(longitude);
    double altitude;
    bool hasAltitude = false;
    altitude = data.value(3).toDouble(&hasAltitude);
    if(hasAltitude)
        coordinate.setAltitude(altitude);
    info.setCoordinate(coordinate);
    
    double HorizontalAccuracy;
    bool hasHorizontalAccuracy = false;
    HorizontalAccuracy = data.value(4).toDouble(&hasHorizontalAccuracy);
    if(hasHorizontalAccuracy)
        info.setAttribute(QGeoPositionInfo::HorizontalAccuracy, HorizontalAccuracy);
    double Direction;
    bool hasDirection = false;
    Direction = data.value(5).toDouble(&hasDirection);
    if(hasDirection)
        info.setAttribute(QGeoPositionInfo::Direction, Direction);
    double GroundSpeed;
    bool hasGroundSpeed = false;
    GroundSpeed = data.value(6).toDouble(&hasGroundSpeed);
    if(hasGroundSpeed)
        info.setAttribute(QGeoPositionInfo::GroundSpeed, GroundSpeed);
    if (info.isValid()) {
        m_lastPosition = info;
        emit positionUpdated(info);
    }
}
コード例 #25
0
void QGeoAreaMonitorSimulator::positionUpdated(const QGeoPositionInfo &info)
{
    qreal distance = info.coordinate().distanceTo(center());

    if (distance <= QGeoAreaMonitor::radius()) {
        if(!insideArea)
            emit areaEntered(info);
        insideArea = true;
    } else if (insideArea) {
        emit areaExited(info);
        insideArea = false;
    }
}
コード例 #26
0
ファイル: Daemon.cpp プロジェクト: GevKostanyan/whowhere
void Daemon::positionUpdated(QGeoPositionInfo gpsPos)
{
    qreal haMeters = 0;

    if(gpsPos.isValid()) {
        haMeters = gpsPos.attribute(QGeoPositionInfo::HorizontalAccuracy);
        log(QString("Location accuracy is %1 m").arg(haMeters));
    } else {
        log("Location updated, but not valid");
    }

    if (!m_daemonEnabled) {
        deleteGPS();
        return;
    }

    if(gpsPos.isValid()) {
        m_YougeoPosInfo = gpsPos;

        if (haMeters < m_accuracy && haMeters != 0) {

            emit gpsLocationReceived();

            if (!m_keepGpsRunning) {
                deleteGPS();
                log(QString("GPS stopped. Accuracy was %1 m").arg(haMeters));
            }
            // Is there location request?
            if (!m_askingLocation.isEmpty()) {
                // Send location response SMS
                m_message->sendLocationSMS("RES:", m_YougeoPosInfo, m_askingLocation);
                log(QString("SMS sent to number %1").arg(m_askingLocation));
                // Reset position and requester
                reset();
            }
        }
    }
}
コード例 #27
0
ファイル: jskitobjects.cpp プロジェクト: ecosprog/pebble
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;
        }
    }
}
コード例 #28
0
ファイル: gps_display.cpp プロジェクト: kjetilk/mapper
void GPSDisplay::positionUpdated(const QGeoPositionInfo& info)
{
    Q_UNUSED(info);

    gps_updated = true;
    tracking_lost = false;
    has_valid_position = true;

    bool ok = false;
    calcLatestGPSCoord(ok);
    if (ok)
    {
        emit mapPositionUpdated(latest_gps_coord, latest_gps_coord_accuracy);
        emit latLonUpdated(
            info.coordinate().latitude(),
            info.coordinate().longitude(),
            (info.coordinate().type() == QGeoCoordinate::Coordinate3D) ? info.coordinate().altitude() : -9999,
            latest_gps_coord_accuracy
        );
    }

    updateMapWidget();
}
コード例 #29
0
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);
}
コード例 #30
0
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));
    }
}