Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.0
- import QtPositioning 5.5
- import QtLocation 5.6
- Rectangle {
- width: 720
- height: 480
- property double latitude: 0
- property double longitude: 0
- property variant deviceLocation: QtPositioning.coordinate(latitude, longitude)
- //! [Initialize Plugin]
- Plugin {
- id: myPlugin
- name: "osm"
- }
- PositionSource {
- id: positionSource
- property variant lastSearchPosition: deviceLocation
- active: true
- updateInterval: 120000 // 2 mins
- onPositionChanged: {
- var currentPosition = positionSource.position.coordinate
- map.center = currentPosition
- var distance = currentPosition.distanceTo(lastSearchPosition)
- if (distance > 500) {
- lastSearchPosition = currentPosition
- searchModel.searchArea = QtPositioning.circle(currentPosition)
- searchModel.update()
- }
- }
- }
- PlaceSearchModel {
- id: searchModel
- plugin: myPlugin
- searchTerm: "Pizza"
- searchArea: QtPositioning.circle(deviceLocation)
- Component.onCompleted: update()
- }
- //! [PlaceSearchModel]
- //! [Places MapItemView]
- Map {
- id: map
- anchors.fill: parent
- plugin: myPlugin;
- center: deviceLocation
- zoomLevel: 13
- MapItemView {
- model: searchModel
- delegate: MapQuickItem {
- coordinate: QtPositioning.coordinate(latitude, longitude)
- anchorPoint.x: image.width * 0.5
- anchorPoint.y: image.height
- sourceItem: Column {
- Image { id: image; source: "marker.png" }
- Text { text: title; font.bold: true }
- }
- }
- }
- }
- //! [Places MapItemView]
- Connections {
- target: searchModel
- onStatusChanged: {
- if (searchModel.status == PlaceSearchModel.Error)
- console.log(searchModel.errorString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement