Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 38
Registered: ‎12-06-2011
My Device: Playbook 64GB, Curve 9360, BB Z10 LE
My Carrier: Koodo
Accepted Solution

Trouble with GPS slot/signal

Hi,

 

I am trying to get GPS information for my app. I have made a class to do this.

 

#ifndef GPSHANDLER_H_
#define GPSHANDLER_H_


#include <QString>

#include <QVariant>

#include <QObject>
#include <QtLocationSubset/QGeoPositionInfo>
#include <QtLocationSubset/QGeoPositionInfoSource>

using namespace QtMobilitySubset;

class GPShandler : public QObject{
	Q_OBJECT
public:
	GPShandler(QObject* parent);
	virtual ~GPShandler();
private Q_SLOTS:
	void positionUpdatedSlot(const QGeoPositionInfo &geoInfo);

public:
	void start();

	void stop();

	double Latitude();

	double Longitude();

private:
	double mGeoInfoLat;
	double mGeoInfoLong;
	QGeoPositionInfoSource *mGeo;
};
#endif /* GPSHANDLER_H_ */

 

#include "GPShandler.h"

GPShandler::GPShandler(QObject* parent)
: QObject(parent) {
	mGeoInfoLat = 0;
	mGeoInfoLong = 0;
	mGeo = QGeoPositionInfoSource::createDefaultSource(this);
	if (mGeo) {
		bool checkval = connect(mGeo, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this,
				SLOT(positionUpdatedSlot(const QGeoPositionInfo &)));


		mGeo->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
		mGeo->setUpdateInterval(1000);

		//checkval = mGeo->setProperty("backgroundMode", true);
		//int i = 3;
	}
}

GPShandler::~GPShandler() {
	// TODO Auto-generated destructor stub
}

void GPShandler::positionUpdatedSlot(const QGeoPositionInfo &geoInfo) {
	// Here's where you can do something with the device's position
	mGeoInfoLat = geoInfo.coordinate().latitude();
	mGeoInfoLong = geoInfo.coordinate().longitude();
}

void GPShandler::start()
{
	mGeo->startUpdates();
}

void GPShandler::stop()
{
	mGeo->stopUpdates();
}

double GPShandler::Latitude()
{
	return mGeoInfoLat;
}

double GPShandler::Longitude()
{
	return mGeoInfoLong;
}

 As you can see I have connected the signal postionUpdate() from QGeo* class I am using to the slot positionUpdatedSlot(). I am using the class like this :

 

mGPS = new GPShandler(this);

 

void App::startTimer() {

 

mGPS->start();

}
void App::stopTimer(){

mGPS->stop();

}

 

which are called when a button is pressed. However the slot function positionUpdatedSlot() is never called. I have debugged through my code and cannot find the problem. I can confirm the connection works (function returns true), and that the stop and start funtions are called as expected. Is there any reason why my slot function is not being called?

 

Note : I do have another signal/slot implementation in this app :

connect(mTimer, SIGNAL(timeout()), this, SLOT(update()));

and this one works fine.

 

Thanks,

 

Gerry

Highlighted
Developer
Posts: 38
Registered: ‎12-06-2011
My Device: Playbook 64GB, Curve 9360, BB Z10 LE
My Carrier: Koodo

Re: Trouble with GPS slot/signal

I'm not sure which of the following solved my problem but in any case it works now after doing these few things :

 

1. Giving app permission to device identifying information. (I had already given GPS, but since some examples also had device identifying information I thought I would try that)

2.  Removing the line : 

 

		mGeo>setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);

 

as a working example I created using this example : http://blackberry.github.com/Cascades-Samples/geo-locationdiagnostics.html did not have that line