QML Geohelper Plugin
Article Metadata
Tested with
Compatibility
Article
Delete the guidance text written in italics.
Overview
Geohelper plugin to expose Qt mobility location geoservice apis to Qml environment
This snippet can be self-signed.
Preconditions
Qt 4.7.1 or newer and Qt mobility 1.1.0 or newer installed
Pro file (optional)
The following capabilities and libraries are required:
CAPABILITY: symbian:TARGET.CAPABILITY = NetworkServices Location ReadUserData WriteUserData
Header file
geohelper.h applying this macro to definitions of member functions to allow them to be invoked via the meta-object system
#ifndef GEOHELPER_H
#define GEOHELPER_H
#include <QObject>
#include <QMap>
#include <QGeoServiceProvider>
#include <QGeoMappingManager>
#include <QGeoSearchManager>
#include <QGeoRoutingManager>
#include <QDeclarativeEngine>
#include <QGeoRouteReply>
#include <QGeoRouteRequest>
#include <QGeoCoordinate>
#include <QDeclarativeItem>
#include <QGeoMapPolylineObject>
#include <QGeoMapPixmapObject>
#include <QGeoMapTextObject>
QTM_USE_NAMESPACE
class GeoHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(QDeclarativeItem* map READ map WRITE setMap)
public:
explicit GeoHelper(QObject *parent = 0);
~GeoHelper();
QDeclarativeItem *map() const {return mapitem; }
void setMap(QDeclarativeItem *map) { mapitem = map; listRef = QDeclarativeListReference(mapitem, "objects");};
Q_INVOKABLE void findRoute(double fromLatitude, double fromLongitude, double toLatitude, double toLongitude);
Q_INVOKABLE void findAddress(double latitude, double longitude);
Q_INVOKABLE void findCoordinates(QString street, QString city, QString country = QString("FINLAND"));
Q_INVOKABLE void clearMap();
Q_INVOKABLE void removeFromMap(QString id);
Q_INVOKABLE void drawPolyline(QString id, QString coordinateArr);
Q_INVOKABLE void drawImage(QString id, double latitude, double longitude, QString imagepath, int xOffset, int yOffset);
Q_INVOKABLE void drawText(QString id, double latitude, double longitude, QString text);
Q_INVOKABLE void findObjectsInCoordinates(double latitude, double longitude);
signals:
void searchError(const QString &error);
void routingError(const QString &error);
void searchReply(const QString &reply);
void routingReply(const QString &reply);
void geomapobjectSelected(QString id, bool selected);
void debugMsg(const QString &reply);
private slots:
void searchErrorSlot(QGeoSearchReply *reply, QGeoSearchReply::Error error, QString errorString = QString());
void searchFinishedSlot(QGeoSearchReply *reply);
void routingErrorSlot(QGeoRouteReply *reply, QGeoRouteReply::Error error, QString errorString);
void routingFinishedSlot(QGeoRouteReply * reply);
private:
QGeoServiceProvider* provider;
QGeoMappingManager* mappingManager;
QGeoSearchManager* searchManager;
QGeoRoutingManager* routingManager;
QDeclarativeContext* context;
QDeclarativeItem* mapitem;
QMap<QString, QGeoMapObject *> mapobjects;
QDeclarativeListReference listRef;
};
#endif // GEOHELPER_H
Source file
Not the complete file but relevant code blocks.
You do not need to provide complete error handling but it should be commented as TODO for developers.
code
Postconditions
Explain what the code snippet is expected to do.
Test application and other attachments (optional)
The attachments should be provided with the visible info page (Categories need to be defined, the attached file must be uploaded to Wiki, and internal Wiki links must be used). Every attachment should have its own page (however, a ZIP package can be used for multiple source code files).

