BlackBerry Java to BlackBerry 10 Cascades Porting Series – Part 9: Location

Native SDK Development

In this part of the porting series we’re going to cover Location APIs to acquire the geo position of a device.

Geo Positioning

Integrating geo positioning in your app is a breeze. Speaking at a high level, BlackBerry 10 supports the following positioning sources.

Multiple Fixes

With only 3 lines of code, you can start a location session for periodic updates.

// Create the position source
QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(this); 
// connect the signal to listen for position updates
connect(_positionSource, 
	SIGNAL(positionUpdated(const QGeoPositionInfo &)),
	this, 
	SLOT(positionUpdated(const QGeoPositionInfo &))
)
// Start updates
source->startUpdates();

While this is quick and easy, you can also control other parameters such as the position source or the interval at which location fixes are sent to your slot.

Single Fix

To query for a single location fix, simply change the last line to:

// Request a single update
source->requestUpdate();

Sample App
A comprehensive and open source sample application is available at:

https://github.com/blackberry/Cascades-Samples/tree/master/locationdiagnostics

Documentation
You can also read the developer documentation for Location here:

https://developer.blackberry.com/cascades/documentation/device_platform/location/index.html

API Documentation

https://developer.blackberry.com/cascades/reference/qtmobilitysubset__qgeopositioninfosource.html

About Shadid

Application Development Consultant at Research In Motion (RIM), Shadid is a developer and more importantly a developer developer. He has been working closely with the dev community to help bring the best BlackBerry® experience to their applications. A key contributor in the Developer Relations team, Shadid is the lead contact for Location Bases Services, Sensors, Bluetooth and Deep Integration of Apps. Working with BlackBerry developers is not just his job but a passion he shares with the BlackBerry developer community.

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus