I am developing cross platform application using QT for Android,iOS,windows. I want to get device current location. I am using Qt Positioning Api. I have written C++ code using the Samples available. Application want to update device location at specified time interval(x seconds) or specified distance(y meters) in meters. Please find the bellow sample code written. Code is causing lot of battery drain almost 9% of the entire battery life also takes lot of time to update first location if network is off.As requirement is to update device location continuously at specified time interval, can't stop location updates QGeoPositionInfoSource
Locationhandler.h
#ifndef LOCATIONHANDLER_H
#define LOCATIONHANDLER_H
#include <QObject>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QDebug>
#include "main.h"
class LocationHandler : public QObject
{
Q_OBJECT
public :
explicit LocationHandler(QObject *parent = 0);
QGeoCoordinate getCurrentLocation();
private :
QGeoCoordinate currentLocation;
QGeoPositionInfoSource *source;
signals :
public slots :
void positionUpdated(const QGeoPositionInfo &info);
};
#endif // LOCATIONHANDLER_H
locationhandler.cpp
#include "LocationHandler.h"
LocationHandler::LocationHandler(QObject *parent) : QObject(parent)
{
source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->startUpdates();
source->setUpdateInterval(60);
}
}
void LocationHandler::positionUpdated(const QGeoPositionInfo &info)
{
if(info.isValid())
{
currentLocation = info.coordinate();
qDebug() << "Current Latitude : " << currentLocation.latitude();
qDebug() << "Current Longitude : " << currentLocation.longitude();
updateDeviceCordinate(currentLocation);
}
}
please let me know,
- Is there any way where i can specify the GPS update interval in terms of Time and Distance which can reduce CPU active time.
- Also I want to know is there any direct way where i can get device location directly using QT API without any(QT Signal) callback function quickly.
Note : qml based location update may not be helpful as we want to implement functionality in C++ code.