Михаиллл
2 июля 2019 г. 23:36

Как получить координаты карты в Qt

Добрый день.
Пытаюсь получить координаты из карты, но программа их не возвращает.
Скажите пожалуйста, что не правильно и что нужно исправить, что бы получить координаты?

  1. import QtQuick 2.12
  2. import QtQuick.Window 2.12
  3. import QtLocation 5.12
  4. import QtPositioning 5.12
  5.  
  6. Item {
  7. visible: true
  8. width: 480
  9. height: 720
  10.  
  11. property double old : 19
  12. property double now
  13.  
  14.  
  15. Rectangle
  16. {
  17. anchors.fill: parent
  18. color: "#eee"
  19.  
  20.  
  21. PositionSource
  22. {
  23. id: src
  24. active: true
  25. updateInterval: 1000
  26. onPositionChanged:
  27. {
  28. console.log("PositionSource:" )
  29. }
  30. }
  31.  
  32. Plugin
  33. {
  34. id: plugin
  35. name: "osm"
  36. PluginParameter { name: "osm.useragent"; value: "My great Qt OSM application" }
  37. PluginParameter { name: "osm.mapping.host"; value: "http://osm.tile.server.address/" }
  38. PluginParameter { name: "osm.mapping.copyright"; value: "All mine" }
  39. PluginParameter { name: "osm.routing.host"; value: "http://osrm.server.address/viaroute" }
  40. PluginParameter { name: "osm.geocoding.host"; value: "http://geocoding.server.address" }
  41. PluginParameter { name: "osm.places.host"; value: "http://geocoding.server.address" }
  42. }
  43.  
  44. Map
  45. {
  46. id: maps
  47. anchors.fill: parent
  48. plugin: plugin
  49. gesture.enabled: true
  50. gesture.acceptedGestures: MapGestureArea.PinchGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
  51. gesture.flickDeceleration: 3000
  52. zoomLevel: 19
  53. center: QtPositioning.coordinate(59.91, 10.75) // Oslo
  54.  
  55. onZoomLevelChanged:
  56. {
  57. console.log("onZoomLevelChanged:")
  58. }
  59.  
  60. onCenterChanged:
  61. {
  62. console.log("onCenterChanged:")
  63. console.log("coordinate:" + src.position.coordinate)
  64. }
  65.  
  66. minimumZoomLevel: 1
  67.  
  68. focus: true
  69.  
  70. }
  71. }
  72. }
  73.  
1

Вам это нравится? Поделитесь в социальных сетях!

2
Михаиллл
  • 2 июля 2019 г. 23:46

Так можно найти центр.
Но как можно определить размеры видимой карты?

  1. console.log("coordinate ctnter:" + visibleRegion.center())
    Михаиллл
    • 2 июля 2019 г. 23:56
    • Ответ был помечен как решение.

    Так работает

    1. console.log("coordinate ctnter:" + visibleRegion.center())
    2. console.log("coordinate geoshape:" + visibleRegion.boundingGeoRectangle())

      Комментарии

      Только авторизованные пользователи могут публиковать комментарии.
      Пожалуйста, авторизуйтесь или зарегистрируйтесь