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

New Contributor
Posts: 3
Registered: ‎07-04-2013
My Device: z10
My Carrier: 9052462650

Location Services Question


I was wondering in what cases things such as the ground speed, altitude, etc.. would return as a NaN? I understand why it happens in mathematics, but what processes here would cause this to happen !?

Thank you for your time !

Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Location Services Question

It may depend on the API you're using, and what options you've configured for it.

While the results from a satellite fix should generally include those values (but may not initially, when it's still getting a good fix), some of those APIs are what I'd call "harmonized" and may not be giving you just satellite data.

What might be happening is you're getting a fix from cell tower triangulation (I think these phones finally do that) or even just a WiFi hotspot lookup. Some of those sorts of results would not have enough precision, accuracy, or detail for them to include those extra calculations.

Consider showing some of the code you're using if you want more than that answer...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
New Contributor
Posts: 3
Registered: ‎07-04-2013
My Device: z10
My Carrier: 9052462650

Re: Location Services Question

Sorry I kept it general because I was hoping for a general answer, but here's what I'm doing :

// Set up the position info source.

mGPSSource = QtMobilitySubset::QGeoPositionInfoSource::createDefaultSource(this);


// Set up positioning method, SATELLITE ONLY.


So im grabbing any method that will return, currently testing with wifi because it usually has rather accurate results and I am just trying to figure out the nan problem.

I then connect a positionUpdated signal to a slot that requests the source as so :

// with some timeout handling code.

Then I was just packaging the data having a qDebug for testing. Currently with wifi only, nan is being returned for altitude. I am also doing some other error checking code but it doesn't need to be mentioned here I think.

Thank you.

BlackBerry Development Advisor
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: Location Services Question

[ Edited ]

The altitude comes from the QGeoCoordinate maintained in the QGeoPositionInfo object. A QGeoCoordinate can be 2D or 3D, where 3D implies the altitude is known. Strictly speaking you should test the QGeoCoordinate type before trying to access the altitude:


if ( posInfo.coordinate().type() == QGeoCoordinate::Coordinate3D ) {
    // altitude is valid
} else {
    // altitude is undefined, accessing it will return NAN

 If you know the position info comes from the gps (preferred methods set to QGeoPositionInfoSource::SatellitePositioningMethods) then the coordinate will always be 3D, but if the source is cellsite or wifi the coordinate will be 2D. Though this may change in the future; if a device has an altimeter then all positioning methods may provide 3D coordinates. Thus it is a good idea to always test the coordinate type in your code.

New Contributor
Posts: 3
Registered: ‎07-04-2013
My Device: z10
My Carrier: 9052462650

Re: Location Services Question

Thank you !