Mobile device users expect your app to be aware of the location of their devices. For example, a weather app can use the location of a device to display the current weather conditions, even when the user is traveling. A social app can use a device's current location to update the user's status. Navigational apps can monitor a device's location periodically to provide traffic updates and estimated arrival times.
The following location services are available in Cascades:
- Positioning: Find the location of a device using GPS satellites, cell ID, or Wi-Fi positioning.
- Geocoding: Find coordinates for a street address (geocoding), or find a street address for geospatial coordinates (reverse geocoding).
- Mapping: Display a location in a MapView or integrate with the BlackBerry Maps application.
The positioning and geocoding classes in Cascades are based on a subset of the Qt Mobility location APIs.
To use positioning and geocoding in your app, include the classes you need from the QtLocationSubset library and use the QtMobilitySubset namespace. Here's an example:
#include <QtLocationSubset/QGeoPositionInfo> #include <QtLocationSubset/QGeoPositionInfoSource> #include <QtLocationSubset/QGeoSatelliteInfo> #include <QtLocationSubset/QGeoSatelliteInfoSource> #include <bb/cascades/maps/MapView> #include <bb/cascades/maps/ViewProperties> #include <bb/platform/geo/BoundingBox.hpp> using namespace bb::cascades; using namespace QtMobilitySubset; using namespace bb::cascades::maps; using namespace bb::platform::geo;
Mapping classes, such as MapView, are located in the Cascades maps library and use the bb::cascades::maps namespace. Geographic classes, such as BoundingBox, are located in the platform library and use the bb::platform::geo namespace. Location services in Cascades aren't available in QML.
To use location services, you must add the following line to the .pro file in your project:
LIBS += -lQtLocationSubset
To enable your app to obtain the current position or last known position of the device, you must add the Location (access_location_services) permission to your bar-descriptor.xml file. You can use all other location services, such as mapping, geocoding, and searching for places, without this permission.
Before a user can use location services, they must be turned on by the user in the settings application of the device. By default, location services are turned off on the device. When the user turns on location services, your app must still request permission to use the device's location services.
Let's learn about how to use location services in your app. You need to set up a location source first, and then you can retrieve a location, which is also called getting a location fix. You can follow along in the resources below or you can jump right into the location diagnostics app in the Sample apps.
Last modified: 2015-05-07