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
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: Getting the device's location

[ Edited ]

Are you saying that the ApplicationUI:: positionUpdateTimeout() method is not getting called when you disable Location Services while your app is running?

 

Which NDK version are you using?

New Developer
RadioRaiders
Posts: 13
Registered: ‎02-17-2010
My Device: Z10

Re: Getting the device's location

[ Edited ]

Actually, when I disable the location, that is reflected and acting as normal.

The problem is when I leave GPS coverage it does not timeout.

I am using only GPS:

    _source->setPreferredPositioningMethods( QtMobilitySubset::QGeoPositionInfoSource::SatellitePositioningMethods);

    _source->setProperty("fixType", "gps_autonomous");

    _source->setUpdateInterval(1000);
    //_source->setProperty( "period", 1.0 );
    //_source->requestUpdate(1000);
    //_source->setProperty( "responseTime", 1.0 );


    _source->startUpdates();

 I am trying to update the values once every second, and if the GPS signal is lost, then to reflect that with an on-screen message via the TimeOut. I have tried all of the variants above that are commented out, but none work.

 

The problem is I am outside and get a GPS lock (and time-stamp), then go inside until the time-stamp stops updating (ie: GPS signal is lost). But instead of the TimeOut triggering to call positionUpdateTimeout() nothing happens and my screen stay stuck on the last valid info from the GPS (ie: coordinates and time-stamp remain there instead of being over-written by TimeOut info)

 

I am using SDK 10.2 and a Z10 also on 10.2

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

Re: Getting the device's location

When using startUpdates() there is not a well-defined response time. You  can expect to get updates approximately on the "updateInterval", but if the hardware has trouble getting a position fix it may be much longer before it indicates a timeout. Did you leave it running for a few minutes to see if it ever timed out, when using startUpdates()?) Note that for startUpdates() the BB-specific responseTime property is only relevant for the first update. In other words if you set the responseTime property and then call startUpates(), if the first update cannot be provided within the responseTime you should get a timeout right after responseTime has elapsed. Subsequently after a successful first update, if a fix can't be attained, when you receive the timeout signal is hardware dependent.

 

So to use startUpdates() and give the user some feedback if an update takes longer than a second (or a few seconds is perhaps reasonable to wait?) you could use a QTimer (restart it in your positionUpdated() slot) which, if triggered, initiates "getting position fix is taking longer than expected" feedback.

 

Alternatively, you can use requestUpdate(). Control it again using a QTimer, or just call it directly from your positionUpdated() slot if one second updates is what you want. If you call requestUpdate(1000) and the gps cannot get a fix within a second you should get a timeout right after a second. Having said that I know there was a bug, which should be fixed in 10.2.1, that resulted in the timeout signal not being emitted properly. The workaround is to set the responseTime property to some value greater than zero and then call requestUpdate(), passing it the desired response time:

 

    _source->setProperty( "responseTime", 1.0 );    
    _source->requestUpdate(1000);
    

 

Did you try this combination?

New Developer
RadioRaiders
Posts: 13
Registered: ‎02-17-2010
My Device: Z10

Re: Getting the device's location

[ Edited ]

Putting the code below in the first line of the positionUpdated() slot seems to do the trick. Thanks :smileyhappy:

 

PS- One other bug: if the app is running, and I disable Location Services, the app recognizes that normally, but when I minimize the app, and re-enable the Location Services, and return to the app, the app still says that Location Services are disabled. I need to re-start the app to get it to see the GPS again.

 

   _source->setProperty( "responseTime", 1.0 );    
    _source->requestUpdate(1000);
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: Getting the device's location

That sounds strange. Does your app call requestUpdate() specifically when the app returns to the foreground? If the only place requestUpdate() is called from your app is in your positionUpdated() slot, then if a timeout is encountered requestUpdate() won't get called again (because your positionUpdated() slot won't get called).

 

Assuming you have a "bb::cascades::Application * app" available you can detect when the app returns to the foreground. Make a connection in the ApplicationUI constructor:

 

    // in case the user disables then later enables location services, test and restart position updates if so when this app's state changes to fullscreen.
    connect(app, SIGNAL(fullscreen()), this, SLOT(checkLocationServicesEnabled()));

 

and add the slot like so:

 

void ApplicationUI::checkLocationServicesEnabled()
{
    if ( _source->property("locationServicesEnabled").toBool() ) {
        // restart the updates
        _source->requestUpdate(1000);
    }
}

 Checking if location services is enabled is ultimately optional, it doesn't really hurt to blindly call requestUpdate() when returning to the foreground.

New Developer
RadioRaiders
Posts: 13
Registered: ‎02-17-2010
My Device: Z10

Re: Getting the device's location


jehrismann wrote:

That sounds strange. Does your app call requestUpdate() specifically when the app returns to the foreground? If the only place requestUpdate() is called from your app is in your positionUpdated() slot, then if a timeout is encountered requestUpdate() won't get called again (because your positionUpdated() slot won't get called).

 

Assuming you have a "bb::cascades::Application * app" available you can detect when the app returns to the foreground. Make a connection in the ApplicationUI constructor:

 

    // in case the user disables then later enables location services, test and restart position updates if so when this app's state changes to fullscreen.
    connect(app, SIGNAL(fullscreen()), this, SLOT(checkLocationServicesEnabled()));

 

and add the slot like so:

 

void ApplicationUI::checkLocationServicesEnabled()
{
    if ( _source->property("locationServicesEnabled").toBool() ) {
        // restart the updates
        _source->requestUpdate(1000);
    }
}

 Checking if location services is enabled is ultimately optional, it doesn't really hurt to blindly call requestUpdate() when returning to the foreground.


Yes, the only place where requestUpdate() is called is in the positionUpdated() slot. However, I don't have any problem going in and out of GPS coverage and minimizing/maximizing the app while it's running, it still gets updates and timeouts as expected. The problem only happens when Location Services is disabled, then I minimize the app to enable it, and return to the app, it still says Location Services is disabled.

 

In any case, the trick you gave worked, thanks again :smileyhappy:

New Developer
RadioRaiders
Posts: 13
Registered: ‎02-17-2010
My Device: Z10

Re: Getting the device's location

private:

    /**
     * Starts to monitor updates in the number of satellites.
     */
    void startSatelliteMonitor();


    QGeoSatelliteInfoSource* satelliteInfoSource;
};

 

applicationui.cpp

void startSatelliteMonitor()
{
	// Connect the satellitesInUseUpdated() signal to a slot
	       // that handles satellites in use.

	       satelliteInfoSource =
	               QGeoSatelliteInfoSource::createDefaultSource(this);

	       bool inUseSlotConnected = connect(satelliteInfoSource,
	          SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)),
	          this,
	          SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));
	       satelliteInfoSource->startUpdates();

}



void satellitesInViewUpdated(
        const QList<QGeoSatelliteInfo> &satellites) {
	std::cout << " sats view   " << std::endl;
}

 I am trying to get the number of satellites in view returned in BB10, based on this Nokia Qt example:

http://developer.nokia.com/community/wiki/Retrieving_satellite_information_in_Qt

 

But it doesn't seem to work for me.

I have also tried this BB example, that does work, but I don't see how to actually return the number of satellites in view:

https://developer.blackberry.com/native/documentation/cascades/device_platform/location/satelliteinf...

 

Any help is much appreciated. Thanks.

 

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

Re: Getting the device's location

Your satellitesInViewUpdated() slot is passed a QList of satellite info objects. The size of the list tells you the number of satellites in view:

 

 

void satellitesInViewUpdated(
        const QList<QGeoSatelliteInfo> &satellites) {
	std::cout << " sats in view: " << satellites.size() << std::endl;
}