Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Strange Error, can't run if i put addPinAtCurrentMapCenter() from mapView

[ Edited ]

hi all

i found strange error that my app cant run at all

this is my new project.

i just want to migrate the mapview sample which MapViewDemo.cpp

i just need a marker for my mapview

this is my code

 

applicationUI.cpp

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
#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/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;
ApplicationUI::ApplicationUI() :
        QObject()
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);

    bool res = QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()));
   
    Q_ASSERT(res);
   
    Q_UNUSED(res);

    onSystemLanguageChanged();

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
  qml->setContextProperty("_mapViewTest", this);
    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    //Application::instance()->setScene(root);
    bb::cascades::Application::instance()->setScene(root);
}
void ApplicationUI::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);

        // use the marker in the assets, as opposed to the default marker
        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 ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("MapView1_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 applicationUI.hpp

#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_

#include <QObject>
//#include <QtNetwork>

namespace bb{
namespace cascades{

        namespace maps {
                      class MapView;
                }
        class LocaleHandler;
    }
namespace platform {
        namespace geo {
        class GeoLocation;
        }
        }
}



class QTranslator;

/*!
 * @brief Application UI object
 *
 * Use this object to create and init app UI, to create context objects, to register the new meta types etc.
 */
class ApplicationUI : public QObject
{
    Q_OBJECT
public:
    ApplicationUI();

    Q_INVOKABLE void addPinAtCurrentMapCenter();
    virtual ~ApplicationUI() {}

private slots:
    void onSystemLanguageChanged();
private:
    QTranslator* m_pTranslator;
    bb::cascades::LocaleHandler* m_pLocaleHandler;
    bb::cascades::maps::MapView* mapView;
        bb::platform::geo::GeoLocation* deviceLocation;
};

#endif 

 main.qml

import bb.cascades 1.3
import QtMobility.sensors 1.2
import bb.cascades.maps 1.0
import QtMobilitySubset.location 1.1


Page {
    onCreationCompleted:{
        _mapViewTest.addPinAtCurrentMapCenter();
    }
    Container {
        MapView {
            id: map
            preferredWidth: Infinity
            preferredHeight: 600
            altitude: 1000
            latitude: 43.449488
            longitude: -80.406777
        
        }
    }
}

 but the result when i run,D:\....... arm\o.le-v7-g\MapView1 not found and my app turns to x

any solution? thanks

Retired
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: Strange Error, can't run if i put addPinAtCurrentMapCenter() from mapView

Hi,
Not sure what you mean by "app turns to x". Can you provide detailed console error output?

Shadid
Highlighted
Developer
Posts: 358
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: Strange Error, can't run if i put addPinAtCurrentMapCenter() from mapView

[ Edited ]

Looks like you don't have the positionsource and mapview object that you place in the main C++ objects from the sample. That add pin code is referencing it. You don't actually have anything defining "MapView" in the cpp code.

Honestly it's a pain transferring all the stuff over from the mapview example, I would just use the mapview app as a base and build your app around it.

 

Trust me I've done it with one of my apps a while ago and it was confusing especially as a novice developer.