MapViewDemo.cpp Example File
mapview/src/MapViewDemo.cpp
#include "MapViewDemo.hpp"
#include <bb/cascades/AbstractPane>
#include <bb/cascades/Application>
#include <bb/cascades/Container>
#include <bb/cascades/maps/MapView>
#include <bb/cascades/maps/MapData>
#include <bb/cascades/maps/DataProvider>
#include <bb/cascades/QmlDocument>
#include <bb/platform/geo/Point>
#include <bb/platform/geo/GeoLocation>
#include <bb/platform/geo/Marker>
#include <bb/UIToolkitSupport>
using namespace bb;
using namespace bb::cascades;
using namespace bb::cascades::maps;
using namespace bb::platform::geo;
MapViewDemo::MapViewDemo(bb::cascades::Application *app)
: QObject(app)
{
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_mapViewTest", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
QObject* mapViewAsQObject = root->findChild<QObject*>(QString("mapViewObj"));
if (mapViewAsQObject) {
mapView = qobject_cast<bb::cascades::maps::MapView*>(mapViewAsQObject);
mapView->setCaptionGoButtonVisible(true);
if (mapView) {
DataProvider* deviceLocDataProv = new DataProvider("device-location-data-provider");
mapView->mapData()->addProvider(deviceLocDataProv);
deviceLocation = new GeoLocation("device-location-id");
deviceLocation->setName("Current Device Location");
deviceLocation->setDescription("<html><a href=\"http://www.blackberry.com\">Hyperlinks</a> are super useful in bubbles.</html>");
Marker bullseye = Marker(UIToolkitSupport::absolutePathFromUrl(
QUrl("asset:///images/me.png")), QSize(60, 60),
QPoint(29, 29), QPoint(29, 1));
deviceLocation->setMarker(bullseye);
deviceLocDataProv->add(deviceLocation);
}
}
app->setScene(root);
}
void MapViewDemo::addPinAtCurrentMapCenter() {
if (mapView) {
GeoLocation* newDrop = new GeoLocation();
newDrop->setLatitude(mapView->latitude());
newDrop->setLongitude(mapView->longitude());
QString desc = QString("Coordinates: %1, %2").arg(mapView->latitude(),
0, 'f', 3).arg(mapView->longitude(), 0, 'f', 3);
newDrop->setName("Dropped Pin");
newDrop->setDescription(desc);
Marker flag;
flag.setIconUri(UIToolkitSupport::absolutePathFromUrl(
QUrl("asset:///images/on_map_pin.png")));
flag.setIconSize(QSize(60, 60));
flag.setLocationCoordinate(QPoint(20, 59));
flag.setCaptionTailCoordinate(QPoint(20, 1));
newDrop->setMarker(flag);
mapView->mapData()->add(newDrop);
}
}
void MapViewDemo::clearPins() {
if (mapView) {
mapView->mapData()->defaultProvider()->clear();
}
}
void MapViewDemo::updateDeviceLocation(double lat, double lon) {
qDebug() << "MapViewDemo::updateDeviceLocation( " << lat << ", " << lon
<< " )";
if (deviceLocation) {
deviceLocation->setLatitude(lat);
deviceLocation->setLongitude(lon);
}
mapView->setLatitude(lat);
mapView->setLongitude(lon);
}