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); ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.