HI i want to get user location coordinates without going to its map page like this link i followed. It works only on map page
Get the path covered by user and display current location
So that i can show user history on map even when it switched to any other page of application.
Is their any way so that even when a user is not on map page my app get its coordinates.
This is the code i edited for map page only.
import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.6
Rectangle {
id: rootRectangle
clip: true
width: 800
height: 600
readonly property int initialZoomScale: 8000
property bool trackingEnabled: false
property Point lastPosition: null
// add a mapView component
MapView {
anchors.fill: parent
Map {
BasemapDarkGrayCanvasVector {}
}
// set initial viewpoint near UCLA, Los Angeles
ViewpointCenter {
Point {
x: -13185535.98
y: 4037766.28
}
targetScale: initialZoomScale
}
Button {
id: button
text: trackingEnabled ? "Stop tracking" : "Start tracking"
anchors.horizontalCenter: parent.horizontalCenter
width: 200
onClicked: trackingEnabled =! trackingEnabled
}
// if tracking is enabled then show location history
locationDisplay.onLocationChanged: {
if (!trackingEnabled)
return;
if (lastPosition !== null) {
polylineBuilder.addPoint(lastPosition);
}
// update last position
lastPosition = locationDisplay.location.position;
console.log(JSON.stringify(lastPosition.json));
// update the polyline
locationHistoryLineOverlay.graphics.append(ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: polylineBuilder.geometry}));
console.log(JSON.stringify(polylineBuilder.geometry.json.paths));
}
Component.onCompleted: {
locationDisplay.autoPanMode = Enums.LocationDisplayAutoPanModeCompassNavigation;
locationDisplay.start();
}
GraphicsOverlay {
id: locationHistoryLineOverlay
SimpleRenderer {
SimpleLineSymbol {
color: "blue"
style: Enums.SimpleLineSymbolStyleDash
width: 5
}
}
}
}//End Mapview
PolylineBuilder {
id: polylineBuilder
spatialReference: SpatialReference { wkid: 4326 }
}
}