O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting device location

Some modern games require information about the player's geographic location and other related data, such as movement speed. The Qt Positioning module allows you to access this information. Let's see a basic QML example of determining the location:

import QtQuick 2.9import QtQuick.Window 2.2import QtPositioning 5.0Window {    visible: true    width: 640    height: 480    title: qsTr("Hello World")    Text {        anchors.centerIn: parent        text: {            var pos = positionSource.position;            var coordinate = pos.coordinate;            return "latitude: " + coordinate.latitude +              "\nlongitude: " + coordinate.longitude;        }    }    PositionSource {        id: positionSource        active: true        onPositionChanged: {            console.log("pos changed",                        position.coordinate.latitude, position.coordinate.longitude); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required