2011-07-04 5 views
0

qt에서 gps 데이터를 사용하여 속도와 거리를 얻을 수있는 방법은 무엇입니까? 나는 그런 수업을 가지고있다. 아마도 어떤 standart 방법 일까?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

우선 페치 (이론적으로) geoPositionInfo.attribute(QGeoPositionInfo::GroundSpeed)

에 의해 할 수있다 source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

groundspeed을하지만 geoPositionInfo.hasAttribute(QGeoPositionInfo::GroundSpeed) == true 가 AFAIK 여러 모바일 장치에서 groundspeed 몇 가지 문제가 있는지 확인합니다.

관련 문제