Skip to content

Record GPS Position Log

In this guide you will learn how to play back a previously recorded GPS position log, using DataSource on an interactive map, and use this as input to record a GPS position log using DataSourceRecorder. A frame per second (FPS) counter is also displayed.

GPS Log Data Source

QML data source GPS position playback and record example

First, get an API key token, see the Getting Started guide.

Qt should be installed to continue.

The Maps SDK for Qt should be installed, see the Setup Maps SDK for Qt guide.


RecordGPSPositionLog demonstrates how easy it is to record a GPS position log using a previously recorded GPS position log file as input, so that GPS log recording can be demonstrated on a desktop computer as well. Typically, the GPS log data source is the GPS sensor on a device, such as a phone.
The previously recorded GPS log input can be a *.nmea file, which can also be generated using free web-based nmea generator tools, or a *.gm file, such as the one generated by this example.

How it works

In Qt, go to the File menu and select Open File or Project…

then browse to the RecordGPSPositionLog example folder and open

You may want to have a look at Setting your API Key to see how to open and configure a project and set your API Key.

In main.qml, in the Component.onCompleted: block, the datasource is set by specifying the filename of a previously recorded (or web-generated) [GPS] position log, strasbourg.nmea in this case:

1ServicesManager.dataSource.playbackFile = Qt.resolvedUrl("strasbourg.nmea");
2ServicesManager.dataSource.type = DataSource.Type.Playback;

This implies that the strasbourg.nmea data file is located in the project directory of this example, and configured in the qml.qrc file, so that Qt.resolvedUrl() can find it.

Additionally, the following options are set for the GPS log data source recorder:

1ServicesManager.dataSourceRecorder.setChunkDurationMinutes = 1;
2ServicesManager.dataSourceRecorder.setContinuousRecording = true;
3ServicesManager.dataSourceRecorder.setDeleteOlderThanKeepMin = false;
4ServicesManager.dataSourceRecorder.setKeepMinMinutes = 60;
The minimum size of a GPS log is 1 minute, set in setChunkDurationMinutes; the setKeepMinMinutes setting specifies the size of the moving window of recorded GPS log data to keep, implying that data older than this amount of time, in minutes, is deleted.
The setDeleteOlderThanKeepMin flag set to false indicates that no data shall be deleted, all recorded GPS log data is kept. This may be useful for testing purposes.

The content type that will be downloaded upon demand is also specified:

let updater = ServicesManager.contentUpdater(ContentItem.Type.RoadMap);

The MapView displaying the interactive map has 4 buttons:

Start / Stop recording and Faster / Slower playback in the top left corner;
Playback - switch to live / Live - switch to playback in the lower left corner; and
Follow position in the lower right corner.
QML data source GPS position playback and record example

The Live/Playback data source must be selected before recording starts. To demonstrate GPS log recording functionality on a desktop computer, a playback data source (.nmea file included in this example) is used, so Playback is selected. Then click Follow position so the camera follows the green position arrow, and click Start recording to start the GPS logger.

Follow position means that the camera flies to the position of the green arrow and then follows the simulated position arrow. This is necessary, as the arrow is likely to be located elsewhere on the map, not at the current location of the camera.

The green position arrow plays back the previously recorded positions on the map, from the data source specified above.

QML data source GPS position playback and record example

If the map is panned/dragged to one side, the camera no longer follows the green position arrow, and the Follow position button is activated again, so it can be clicked to resume following the position arrow. Next, click Faster playback to see that the simulation runs faster.

QML data source GPS position playback and record example

Click Slower playback to see that the simulation runs again at normal speed.

QML data source GPS position playback and record example

Click Stop recording after at least 1 minute elapsed after Start recording was clicked, or after the playback ends, to save the recorded GPS log.

The GPS log file has a .gm extension and is saved in this directory: ~/.local/share/APPNAME/ where APPNAME in this case is the name of this example, RecordGPSPositionLog The .gm file can be used as playback input just like an .nmea GPS log file.

Implementation details

The MapView interactive map has these settings for display and user touch input:

 1id: mapView
 2anchors.fill: parent
 3viewAngle: 25
 4zoomLevel: 69
 5viewPerspective: MapView.ViewPerspective.View3D
 6buildingsVisibility: MapView.BuildingsVisibility.Show3D
 7detailsQualityLevel: MapView.DetailsQualityLevel.Medium
 8gestures: MapView.Gesture.Pan
 9| MapView.Gesture.PanEnableVelocity
10| MapView.Gesture.Pinch
11| MapView.Gesture.Rotate
12| MapView.Gesture.Tilt

anchors.fill: parent causes the map to fill the containing viewport, which is Window in this case. The zoomLevel has a higher value, the closer the camera is to the ground.

1Text {
2   anchors.right: parent.right
4   text: fpsCounter.fps
5   }

The frames-per-second (fps) counter is displayed in the top right corner of the map.

 1Button {
 2   id: livePlaybackButton
 3   enabled: !
 4   anchors.left: parent.left
 5   anchors.bottom: parent.bottom
 6   text: ServicesManager.dataSource.type === DataSource.Type.Live
 7   ? "Live - switch to playback" : "Playback - switch to live"
 8   onClicked: {
 9   ServicesManager.dataSource.type =
10   ServicesManager.dataSource.type === DataSource.Type.Live
11   ? DataSource.Type.Playback : DataSource.Type.Live;
12   }
15The button to switch between live and playback input data source sets

the ServicesManager.dataSource.type qml property to either DataSource.Type.Playback or DataSource.Type.Live

 1Button {
 2   id: startStopButton
 3   text:
 4   ? "Stop recording" : "Start recording"
 5   onClicked: {
 7      ? ServicesManager.dataSourceRecorder.stop()
 8      : ServicesManager.dataSourceRecorder.start();
 9      startStopButton.text =
10      ? "Stop recording" : "Start recording"
11      livePlaybackButton.enabled = !;
12      }
13   }

The start/stop recording button calls the ServicesManager.dataSourceRecorder.start() function if the data source recorder is not active, otherwise, if it is already recording, it calls the ServicesManager.dataSourceRecorder.stop() function. The button also enables the live/playback button if the data source GPS log recorder is turned off by the button click. Otherwise, if the button click turns on the data source GPS log recorder, it also disables the live/playback button, as the position input source should stay the same during a GPS log recording session. The live/playback button is enabled/disabled using its id and the enabled property: livePlaybackButton.enabled

1Button {
2   text: ServicesManager.dataSource.playbackSpeedMultiplier==9
3   ? "Slower playback" : "Faster playback"
4   onClicked: {
5      ServicesManager.dataSource.playbackSpeedMultiplier==9
6      ? ServicesManager.dataSource.playbackSpeedMultiplier=1
7      : ServicesManager.dataSource.playbackSpeedMultiplier=9;
8              }
9      }

The faster/slower playback button toggles the playback speed between 1x (normal) and 9x (visibly fast).

1Button {
2   anchors.right: parent.right
3   anchors.bottom: parent.bottom
4   text: qsTr("Follow position")
5   enabled: !mapView.followingPosition
6   onClicked: mapView.followingPosition = true
7       }

The follow position button is enabled only if the camera is not already following the green position arrow on the map.

2   <qresource prefix="/">
3      <file>main.qml</file>
4      <file>strasbourg.nmea</file>
5   </qresource>

The qml.qrc file lists the strasbourg.nmea GPS position log file.

QML Examples

Maps SDK for Qt Examples can be downloaded or cloned with Git