2011-07-04 15 views
0

qtでgpsデータを使用してスピードと距離をどのように得ることができますか? 私はそのようなクラスを持っていますか?qtモビリティのgpsデータで速度を計算する方法は?

#include "mainwindow.h" 
#include "ui_mainwindow.h" 
#include "quitdiallog.h" 
#include <QGeoCoordinate> 
#include <QDebug> 
#include <QtGui/QMessageBox> 
#include <QList> 
MainWindow::MainWindow(QWidget *parent) : 
    QMainWindow(parent), 
    ui(new Ui::MainWindow) 
{ 
    setWindowTitle("Мой кОмпаС"); 
    ui->setupUi(this); 
    startGPS(); 

} 

MainWindow::~MainWindow() 
{ 
    delete ui; 
} 
void MainWindow::startGPS() 
{ 
    // Obtain the location data source if it is not obtained already 
    if (!locationDataSource) 
    { 
     locationDataSource = 
       QGeoPositionInfoSource::createDefaultSource(this); 
     if (locationDataSource) 
     { 
      // Whenever the location data source signals that the current 
      // position is updated, the positionUpdated function is called. 
      QObject::connect(locationDataSource, 
          SIGNAL(positionUpdated(QGeoPositionInfo)), 
          this, 
          SLOT(positionUpdated(QGeoPositionInfo))); 
      // Start listening for position updates 
        locationDataSource->setUpdateInterval(200); 
      locationDataSource->startUpdates(); 
     } else { 
      // Not able to obtain the location data source 
      // TODO: Error handling 
     } 
    } else { 
     // Start listening for position updates 
     locationDataSource->setUpdateInterval(5000); 
     locationDataSource->startUpdates(); 
    } 
} 

void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo) 
{ 
    if (geoPositionInfo.isValid()) 
    { 
     //locationDataSource->stopUpdates(); 
     QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate(); 
     this->latitude = geoCoordinate.latitude(); 
     this->longitude = geoCoordinate.longitude(); 
     this->altitude=geoCoordinate.altitude(); 
    ui->label->setNum(latitude); 
    ui->label_2->setNum(longitude); 
    } 
} 



void MainWindow::on_pushButton_clicked() 
{ 
    ui->label_3->setNum(latitude); 
    qDebug()<<latitude<<" "<<longitude<<" "<<altitude; 
} 

void MainWindow::on_pushButton_4_clicked() 
{ 
    QuitDiallog *qi=new QuitDiallog; 
    this->hide(); 
    qi->show(); 
} 

速度の取得方法???

答えて

2

最初私はsource->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

を行うだろう対地はgeoPositionInfo.attribute(QGeoPositionInfo::GroundSpeed)

によって(理論的に)フェッチする。しかしgeoPositionInfo.hasAttribute(QGeoPositionInfo::GroundSpeed) == true は、私の知る限り、複数のモバイルデバイス上の対地といくつかの問題があることを確認することができます。

関連する問題