Advertisement
Guest User

dsfsdf

a guest
Apr 6th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 2.10 KB | None | 0 0
  1. import QtQuick 2.0
  2. import QtPositioning 5.5
  3. import QtLocation 5.6
  4.  
  5. Rectangle {
  6.     width: 720
  7.     height: 480
  8.  
  9.     property double latitude:  0
  10.     property double longitude: 0
  11.     property variant deviceLocation: QtPositioning.coordinate(latitude, longitude)
  12.  
  13.     //! [Initialize Plugin]
  14.     Plugin {
  15.         id: myPlugin
  16.         name: "osm"
  17.     }
  18.     PositionSource {
  19.         id: positionSource
  20.         property variant lastSearchPosition: deviceLocation
  21.         active: true
  22.         updateInterval: 120000 // 2 mins
  23.         onPositionChanged:  {
  24.             var currentPosition = positionSource.position.coordinate
  25.             map.center = currentPosition
  26.             var distance = currentPosition.distanceTo(lastSearchPosition)
  27.             if (distance > 500) {
  28.                 lastSearchPosition = currentPosition
  29.                 searchModel.searchArea = QtPositioning.circle(currentPosition)
  30.                 searchModel.update()
  31.             }
  32.         }
  33.     }
  34.  
  35.     PlaceSearchModel {
  36.         id: searchModel
  37.  
  38.         plugin: myPlugin
  39.  
  40.         searchTerm: "Pizza"
  41.         searchArea: QtPositioning.circle(deviceLocation)
  42.  
  43.         Component.onCompleted: update()
  44.     }
  45.     //! [PlaceSearchModel]
  46.  
  47.  
  48.     //! [Places MapItemView]
  49.     Map {
  50.         id: map
  51.         anchors.fill: parent
  52.         plugin: myPlugin;
  53.         center: deviceLocation
  54.         zoomLevel: 13
  55.  
  56.         MapItemView {
  57.             model: searchModel
  58.             delegate: MapQuickItem {
  59.                 coordinate: QtPositioning.coordinate(latitude, longitude)
  60.  
  61.                 anchorPoint.x: image.width * 0.5
  62.                 anchorPoint.y: image.height
  63.  
  64.                 sourceItem: Column {
  65.                     Image { id: image; source: "marker.png" }
  66.                     Text { text: title; font.bold: true }
  67.                 }
  68.             }
  69.         }
  70.     }
  71.     //! [Places MapItemView]
  72.  
  73.     Connections {
  74.         target: searchModel
  75.         onStatusChanged: {
  76.             if (searchModel.status == PlaceSearchModel.Error)
  77.                 console.log(searchModel.errorString());
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement