0

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();
}

スピードを出すには???

4

1 に答える 1

2

最初に私がするだろうsource->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

対地速度は(理論的には)次のように取得できます。geoPositionInfo.attribute(QGeoPositionInfo::GroundSpeed)

geoPositionInfo.hasAttribute(QGeoPositionInfo::GroundSpeed) == true ただし、いくつかのモバイル デバイスでは対地速度に問題があることを確認してください。

于 2011-07-04T17:30:28.190 に答える