QML Maps

Maps deals with maps, their contents and navigation.

Overview

The Map type allows the display of a map and placing objects within the map. Various points of interest can be defined and added to the map for display. Also the Map has features to control how the map is displayed. With the Map item you can center the map, zoom, pinch and make the item flickable.

The places to be added to the map are MapItems . The item’s position is defined by a coordinate which includes latitude, longitude and altitude. The item is then displayed automatically after it is added to the Map .

Position on map

All position APIs are part of the QtPositioning module. The basic piece of position information is the coordinate . A coordinate encapsulates data for the latitude, longitude and altitude of the location. Altitude is in meters. It also has a method to determine distance to another coordinate . The coordinate type may also be held within a Location element, this will also have information on a bounding box size to determine sufficient proximity to the location and a location address.

Here is an example of a client that uses a position source to center a map on the current position:

Rectangle {

    import QtPositioning 5.2
    import QtLocation 5.3
    ...

    Map {
        id: map
        // initialize map
        ...
    }

    PositionSource {
        onPositionChanged: {
            // center the map on the current position
            map.center = position.coordinate
        }
    }
}

Geocoding

Geocoding is the derivation of geographical coordinates (latitude and longitude) from other geographical references to the locations. For example, this can be a street address. Reverse geocoding is also possible with a street address being used to determine a geographical coordinate. Geocoding is performed by using the GeocodeModel type.

The following code examples are a small part of the map component in the Map Viewer (QML) example. The snippets demonstrate the declaration of the GeocodeModel component.

In the snippet we see that the [QML]{ GeocodeModel } contains the plugin and two signal handlers. One for changes in status onStatusChanged :ref:` <qml-qtlocation-geocodemodel.html-status-prop>` and the other to update the centering of the Map object onLocationsChanged :meth:` <GeocodeModel.locationsChanged>` .

GeocodeModel {
    id: geocodeModel
    plugin: map.plugin
    onStatusChanged: {
        if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error))
            map.geocodeFinished()
    }
    onLocationsChanged:
    {
        if (count == 1) {
            map.center.latitude = get(0).coordinate.latitude
            map.center.longitude = get(0).coordinate.longitude
        }
    }
}

MapItemView {
    model: geocodeModel
    delegate: pointDelegate
}

The geocoding features are called from a higher level piece of code. In this snippet we see an Address object filled with the desired parameters.

Address {
    id :fromAddress
    street: "Sandakerveien 116"
    city: "Oslo"
    country: "Norway"
    state : ""
    postalCode: "0484"
}

The Address is later used in a query for the GeocodeModel to process and determine the geographical coordinates .

// send the geocode request
geocodeModel.query = fromAddress
geocodeModel.update()

Zoom, Pinch and Flickable

The Map item also supports user interface interactions with the map using tactile and mouse gestures. That is features such as swiping to pan, pinching to zoom.

Enabling and configuring pinch and flickable is easy within the Map type.

Map {
    id: map
    // Enable pan, flick, and pinch gestures to zoom in and out
    gesture.acceptedGestures: MapGestureArea.PanGesture | MapGestureArea.FlickGesture | MapGestureArea.PinchGesture | MapGestureArea.RotationGesture | MapGestureArea.TiltGesture
    gesture.flickDeceleration: 3000
    gesture.enabled: true
}

Zoom can also be controlled by other objects like sliders, with binding to the Map zoomLevel .

QML Types

Maps

qml-qtlocation-mapcircle.html

The MapCircle type displays a geographic circle on a Map.

qml-qtlocation-map.html

The Map type displays a map.

qml-qtlocation-mapcopyrightnotice.html

The MapCopyrightNotice item displays the current valid copyright notice for a Map element.

qml-qtlocation-mapitemgroup.html

The MapItemGroup type is a container for map items.

qml-qtlocation-mapitemview.html

The MapItemView is used to populate Map from a model.

qml-qtlocation-mapparameter.html

qml-qtlocation-dynamicparameter.html

The DynamicParameter (previously MapParameter ) type represents a parameter for a Map element, or other elements used in a Map (such as map items, etc.). This type provides a mean to specify plugin-dependent optional dynamic parameters that allow a plugin to extend the runtime API of the module.

qml-qtlocation-mapquickitem.html

The MapQuickItem type displays an arbitrary Qt Quick object on a Map.

qml-qtlocation-maptype.html

The MapType type holds information about a map type.

qml-qtlocation-cameracapabilities.html

The CameraCapabilities type holds information about the camera capabilities for a specific map type.

qml-qtlocation-mappolygon.html

The MapPolygon type displays a polygon on a Map.

qml-qtlocation-mappolyline.html

The MapPolyline type displays a polyline on a map.

qml-qtlocation-maprectangle.html

The MapRectangle type displays a rectangle on a Map.

qml-qtlocation-maproute.html

The MapRoute type displays a Route on a Map.

The GeoObject type is a base class for geographical objects that can be added to a map.

qml-qtlocation-mappinchevent.html

MapPinchEvent type provides basic information about pinch event.

qml-qtlocation-mapgesturearea.html

The MapGestureArea type provides Map gesture interaction.

qml-qt-labs-location-navigator.html

The Navigator type offers functionalities to perform turn-by-turn navigation.

qml-qt-labs-location-mapcircleobject.html

The MapCircleObject displays a circle on a Map.

qml-qt-labs-location-mapiconobject.html

The MapIconObject displays an icon on a Map.

qml-qt-labs-location-mapobjectview.html

The MapObjectView is used to populate Map with map objects from a model.

qml-qt-labs-location-mappolygonobject.html

The MapPolygonObject displays a polygon on a Map.

qml-qt-labs-location-mappolylineobject.html

The MapPolylineObject displays a polyline on a Map.

qml-qt-labs-location-maprouteobject.html

The MapRouteObject displays a geographical route on a Map.

Geocoding

qml-qtlocation-geocodemodel.html

The GeocodeModel type provides support for searching operations related to geographic information.

Routing

qml-qtlocation-routemaneuver.html

The RouteManeuver type represents the information relevant to the point at which two RouteSegments meet.

qml-qtlocation-route.html

The Route type represents one geographical route.

qml-qtlocation-routeleg.html

The RouteLeg type represents a leg of a Route, that is the portion of a route between one waypoint and the next.

qml-qtlocation-routemodel.html

The RouteModel type provides access to routes.

qml-qtlocation-routequery.html

The RouteQuery type is used to provide query parameters to a RouteModel.

qml-qtlocation-waypoint.html

The Waypoint type provides a mean to specify a waypoint in a RouteQuery in a more detailed way than by using a simple coordinate.

qml-qtlocation-routesegment.html

The RouteSegment type represents a segment of a Route.

Example

The above snippets are taken from the Map Viewer (QML) example.