如何在qt mobile中通过gps数据计算速度?

发布于 2024-11-18 12:54:36 字数 2406 浏览 6 评论 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();
}

怎么获得速度???

How I can get my speed, and distance by using gps data in qt?
I have such class, maybe is any standart method?

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

How to get speed???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2024-11-25 12:54:36

首先我会做 source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

地速可以通过 geoPositionInfo.attribute(QGeoPositionInfo::GroundSpeed) 获取(理论上)

但是可以确定geoPositionInfo.hasAttribute(QGeoPositionInfo::GroundSpeed) == true
据我所知,一些移动设备上的地面速度存在一些问题。

first i would do source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

The groundspeed can be fetched (theoretically) by geoPositionInfo.attribute(QGeoPositionInfo::GroundSpeed)

But be sure that geoPositionInfo.hasAttribute(QGeoPositionInfo::GroundSpeed) == true
AFAIK there are some issues with groundspeed on several mobile devices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文