MeeGo 1.2 Harmattan Developer Documentation Develop for the Nokia N9

Using location and maps in applications

There is a variety of ways to use location data in applications targeted for mobile devices, ranging from basic navigation to enabling users to share landmarks (places that have a special significance, such as favourite restaurants or public buildings) in a specific geographic area. By incorporating location data into your application, you can provide enhanced services and information and thus improve the user experience. It is easy to use location data as contextual input on a Harmattan device. An application can use the location data as:

  • Input to customise the provided content according to a given location.
    • For example, an application can list restaurants situated near the user's current location.
  • Output to display location data to the user.
    • For example, an application can show nearby restaurants on a map.

On the MeeGo 1.2 Harmattan platform, use the Location API (provided by Qt Mobility) to incorporate location positioning, management of landmarks, and mapping and navigation data and the QML Map element to embed a map of the world into your application's UI.

Location services are available with both QML and C++ code. QML allows you to provide the following location services in your application:

  • Positioning (that is, getting the raw position and velocity data).
  • Map (that is, plotting the location on map).

The following subsections describe basic location services that you can add to your application: determining the device's location and displaying the location on a map.

Note: When a user tries to access location services for the first time, the device automatically requests permission from the user before allowing the application to obtain the user's location. Since the system takes care of this, you do not need to enable this query in any way when developing your application.

Determining the device's location

The Location API determines the location of the device and updates the location data as the user moves. To retrieve the information, the API is able to use the following methods:

  • Global positioning system (GPS), which determines the location according to the radiowave signals received from satellites. The Harmattan device uses a GPS chip to access GPS.
  • Network positioning, for example, Cell ID positioning, which determines the location according to the unique ID of the base station to which the device is currently connected.
  • Hybrid methods, for example, assisted GPS (A-GPS), which uses both GPS and network positioning.

Applications that are continuously running location services (especially through GPS) consume a lot of battery power. It is usually enough if the application determines the initial location of the device, and fetches location data updates at periodical intervals. You can use the system heartbeat feature to decrease the power consumption of applications that frequently update location data.

As with any application, you must ensure that your location-based application behaves properly in different states, depending on its functionality. For more information on application states and how an application should behave in them, see Application lifecycle.

Displaying a map

The main functionality of the QML Map element comes from a map plugin. On the MeeGo 1.2 Harmattan platform, a Nokia Maps plugin is available by default as part of Qt Mobility. For an example of how to access the Nokia Maps plugin, see Example of displaying location data and a map in your application. You can also customise the Map element with overlays (transparent sheets placed over the map to give extra details) and map objects (such as rectangles, circles, text, and images). For a complete list of the available items, see the QGeoMapOverlay class reference and the QML Map element documentation.

When adding the map functionality to your application, you can select from a range of different map types, such as a street map, a satellite map, or a terrain map. You can also add a UI element to your application that allows the user to switch between map types. To make it easier for the users to view the map, you can enable panning and zooming the map view on the Harmattan device. When you have fetched the user's current location, you can display the location on a map.

Note: If you plan to publish an application with a map functionality in Nokia Store, register your application at Nokia Developer. When you have registered your application, you gain credentials (app ID and token) that you can use to make the required Location API calls. By using the app ID and token, you can ensure the long-term functionality of your application.

Further information

For more information on location services and maps, see the following links: