Solved How do I get the map's visible coordinates?
-
Hi!
How do I get the map's visible coordinates?
This my code:import QtQuick 2.12 import QtQuick.Window 2.12 import QtLocation 5.12 import QtPositioning 5.12 Item { visible: true width: 480 height: 720 // width: Screen.width // height: Screen.height property double old : 19 property double now Rectangle { anchors.fill: parent color: "#eee" Component.onCompleted: { circle.center = src.position.coordinate circle1.center = src.position.coordinate circle2.center = src.position.coordinate maps.center = src.position.coordinate } PositionSource { id: src active: true updateInterval: 1000 onPositionChanged: { circle.center = position.coordinate circle1.center = position.coordinate circle2.center = position.coordinate } } Plugin { id: plugin name: "osm" PluginParameter { name: "osm.useragent"; value: "My great Qt OSM application" } PluginParameter { name: "osm.mapping.host"; value: "http://osm.tile.server.address/" } PluginParameter { name: "osm.mapping.copyright"; value: "All mine" } PluginParameter { name: "osm.routing.host"; value: "http://osrm.server.address/viaroute" } PluginParameter { name: "osm.geocoding.host"; value: "http://geocoding.server.address" } PluginParameter { name: "osm.places.host"; value: "http://geocoding.server.address" } } Map { id: maps anchors.fill: parent plugin: plugin gesture.enabled: true gesture.acceptedGestures: MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture gesture.flickDeceleration: 3000 zoomLevel: 19 onZoomLevelChanged: { } minimumZoomLevel: 1 focus: true } } }
-
Tried to do so, but the coordinates are not returned. Please tell me how to do it.
import QtQuick 2.12 import QtQuick.Window 2.12 import QtLocation 5.12 import QtPositioning 5.12 //console.log("открылась Page1") //вывод текста в консоль Item { visible: true width: 480 height: 720 // width: Screen.width // height: Screen.height property double old : 19 property double now Rectangle { anchors.fill: parent color: "#eee" /*Component.onCompleted: { circle.center = src.position.coordinate circle1.center = src.position.coordinate circle2.center = src.position.coordinate maps.center = src.position.coordinate }*/ PositionSource { id: src active: true updateInterval: 1000 onPositionChanged: { console.log("PositionSource:" ) // circle.center = position.coordinate // circle1.center = position.coordinate // circle2.center = position.coordinate } } Plugin { id: plugin name: "osm" PluginParameter { name: "osm.useragent"; value: "My great Qt OSM application" } PluginParameter { name: "osm.mapping.host"; value: "http://osm.tile.server.address/" } PluginParameter { name: "osm.mapping.copyright"; value: "All mine" } PluginParameter { name: "osm.routing.host"; value: "http://osrm.server.address/viaroute" } PluginParameter { name: "osm.geocoding.host"; value: "http://geocoding.server.address" } PluginParameter { name: "osm.places.host"; value: "http://geocoding.server.address" } } Map { id: maps anchors.fill: parent plugin: plugin gesture.enabled: true gesture.acceptedGestures: MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture gesture.flickDeceleration: 3000 zoomLevel: 19 onZoomLevelChanged: { console.log("onZoomLevelChanged:") } onCenterChanged: { console.log("onCenterChanged:") console.log("coordinate:" + src.position.coordinate) } minimumZoomLevel: 1 focus: true /*MapCircle { id: circle z: 2 color: "#fff" radius: 8 border.color: "#fff" center { latitude: src.position.coordinate.latitude longitude: src.position.coordinate.longitude } } MapCircle { id: circle2 z: 3 color: "#0084ff" radius: 4 border.color: "#0084ff" center { latitude: src.position.coordinate.latitude longitude: src.position.coordinate.longitude } } MapCircle { id: circle1 z: 1 color: "#0084ff" border.color: "#0084ff" opacity: 0.25 radius: 19 center { latitude: src.position.coordinate.latitude longitude: src.position.coordinate.longitude } }*/ } } }
-
So you can find the center. But how can you determine the size of the visible map?
console.log("coordinate center:" + visibleRegion.center())
-
It's works
console.log("coordinate ctnter:" + visibleRegion.center()) console.log("coordinate geoshape:" + visibleRegion.boundingGeoRectangle())