IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Places Map (QML)

The Places Map example demonstrates how to search for and display a list of places on a map using a https://.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Places Map (QML)▲

Image non disponible

The example displays a map of the current location or, if no position is available, it uses Brisbane/Australia. Subsequently a search for places matching the term "pizza" is performed and each result shown on the map.

Running the Example▲

To run the example from http://, open the Welcome mode and select the example from Examples. For more information, visit http://.

Local Search▲

 
Sélectionnez
import QtQuick 2.0
import QtPositioning 5.5
import QtLocation 5.6

Instantiate a https:// instance. The https:// is effectively the backend from where places are sourced from. Depending on the chosen plugin some manadatory parameters may be needed. In this case the https:// is selected which does not have any mandatory parameters.

 
Sélectionnez
Plugin {
    id: myPlugin
    name: "osm" // "mapboxgl", "esri", ...
    //specify plugin parameters if necessary
    //PluginParameter {...}
    //PluginParameter {...}
    //...
}

Next we instantiate a https:// which we can use to specify search parameters and perform a places search operation. For illustrative purposes, https://() is invoked once construction of the model is complete. Typically https://() would be invoked in response to a user action such as a button click.

 
Sélectionnez
property variant locationOslo: QtPositioning.coordinate( 59.93, 10.76)

PlaceSearchModel {
    id: searchModel

    plugin: myPlugin

    searchTerm: "Pizza"
    searchArea: QtPositioning.circle(locationOslo)

    Component.onCompleted: update()
}

The map is displayed by using the https:// type and inside we declare the https:// and supply the search model and a delegate. An inline delegate has been used and we have assumed that every search result is of https:// PlaceSerachesult. Consequently it is assumed that we always have access to the place https://, other search result types may not have a place https://.

 
Sélectionnez
Map {
    id: map
    anchors.fill: parent
    plugin: myPlugin;
    center: locationOslo
    zoomLevel: 13

    MapItemView {
        model: searchModel
        delegate: MapQuickItem {
            coordinate: place.location.coordinate

            anchorPoint.x: image.width * 0.5
            anchorPoint.y: image.height

            sourceItem: Column {
                Image { id: image; source: "marker.png" }
                Text { text: title; font.bold: true }
            }
        }
    }
}

Finally, a PositionSource is used to reset the map to the curent location and find "pizza" places in the new area. The position information is updated every 2 minutes and if the new position is more than 500 meters away from the last pizza search area the place search is retriggered.

 
Sélectionnez
PositionSource {
    id: positionSource
    property variant lastSearchPosition: locationOslo
    active: true
    updateInterval: 120000 // 2 mins
    onPositionChanged:  {
        var currentPosition = positionSource.position.coordinate
        map.center = currentPosition
        var distance = currentPosition.distanceTo(lastSearchPosition)
        if (distance > 500) {
            // 500m from last performed pizza search
            lastSearchPosition = currentPosition
            searchModel.searchArea = QtPositioning.circle(currentPosition)
            searchModel.update()
        }
    }
}

List of Files▲

Files:

List of Files▲

  • places_map/main.cpp

  • places_map/places_map.pro

  • places_map/places_map.qml

  • places_map/places_map.qrc

List of Files▲

Images:

List of Files▲
  • places_map/marker.png

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.