Skip To Content

Position display

Geographic position can be incorporated into your app in a number of ways:

  • Show device location either on a map or as coordinates displayed in the user interface.
  • Store device location as coordinates in a file for later use (for example, tracklog).

The map's positionDisplay property is the primary location display choice for your app. Similar to a map grid, position display reacts to map panning and rotation. There is only one position display in your map. If you want to show locations from multiple sources, such as showing current location from your device along with a prerecorded tracklog, you can add the additional source positions using position layers.

The position display is always the topmost layer of the map and can autopan the map as the current location changes. It has fewer properties than a position layer for modifying the symbology used for the location, but is more closely integrated with the map behaviour.

The syntax for adding position display to your map is as follows:

nmeaSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode);
    QString nmeaFilePath = QString("GPS.txt");

    m_DataFile = new QFile(nmeaFilePath);
    if (!m_DataFile->open(QIODevice::ReadOnly))
    {
        qCritical() << Q_FUNC_INFO << "Error opening:" << m_DataFile->fileName();
        return;
    }
    nmeaSource->setDevice(m_DataFile);
    nmeaSource->setUpdateInterval(500);
    m_positionDisplay = m_map->positionDisplay();
    m_positionDisplay->setPositionSource(nmeaSource);

A position layer displays a chosen location on a map. Location can be deduced from any number of sources, most commonly a GPS or location sensor inside, or connected to, your device. Location can also come from a local text file or a feed of locations such as a network stream.

Along with the map's built-in position display, multiple position layers can be defined in a map, allowing you to display location results from different sources. This is great if you need to track multiple field-workers in your project team, or compare results from different sensors.

Unlike the position display, a position layer will not automatically pan the map when the current location changes.

The following example adds a position layer to a map, displaying the contents of the text file GPS.txt, updating the position on the screen each second. In this example no trail or track points are shown.

nmeaSource = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode);
    QString nmeaFilePath = "GPS.txt";
    m_DataFile = new QFile(nmeaFilePath);
    if (!m_DataFile->open(QIODevice::ReadOnly))
    {
        qCritical() << Q_FUNC_INFO << "Error opening:" << m_DataFile->fileName();
        return;
    }
    nmeaSource->setDevice(m_DataFile);
    nmeaSource->setUpdateInterval(1000);
    m_positionLayer = new EsriRuntimeQt::PositionLayer(this);
    m_positionLayer->setShowCourseSymbol(true);
    m_map->addLayer(m_positionLayer);

// ...

void PositionLayerTest::onMapReady()
{
    m_positionLayer->setPositionSource(nmeaSource);
    nmeaSource->startUpdates();
}