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
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

What's the problem with this location handler ?

[ Edited ]

Here is my little location handler

 

#include "LocationDiagnostics.hpp"

GPShandler::GPShandler(QObject* parent)
	: QObject(parent)
	, m_latitude(0)
    , m_longitude(0)
    , m_positionSource(QGeoPositionInfoSource::createDefaultSource(this))
{
	if (m_positionSource) {
	        connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));


	        //log(tr("Initialized QGeoPositionInfoSource"));
	    } else {
	        //log(tr("Failed to initialized QGeoPositionInfoSource"));
	    }
}


void GPShandler::startUpdates()
{
    if (m_positionSource) {
        m_positionSource->startUpdates();
        //log(tr("Position updates started"));
    }


}

void GPShandler::requestUpdate()
{
    if (m_positionSource) {
        m_positionSource->requestUpdate(120000);
        //log(tr("Update requested"));
    }
}

void GPShandler::stopUpdates()
{
    if (m_positionSource) {
        m_positionSource->stopUpdates();
        //log(tr("Position updates stopped"));
    }

    deleteLater();
}

void GPShandler::positionUpdated(const QGeoPositionInfo& pos)
{

    m_latitude = pos.coordinate().latitude();
    m_longitude = pos.coordinate().longitude();


    emit dataChanged();
}
QGeoPositionInfoSource* GPShandler::positionSource() const
{
    return m_positionSource;
}
double GPShandler::latitude() const
{
    return m_latitude;
}

double GPShandler::longitude() const
{
    return m_longitude;
}

 

#ifndef GPSHANDLER_H_
#define GPSHANDLER_H_

#include 
#include 
#include 
#include 
#include 
#include 

using namespace QtMobilitySubset;

class GPShandler : public QObject{
	Q_OBJECT


	  Q_PROPERTY(double latitude READ latitude NOTIFY dataChanged)
	  Q_PROPERTY(double longitude READ longitude NOTIFY dataChanged)




public:
	GPShandler(QObject* parent);
	//virtual ~GPShandler();


	Q_INVOKABLE void startUpdates();

	    // This method is called to trigger an one-time retrieval of location information
		Q_INVOKABLE void requestUpdate();

	    // The accessor method for the internal geo position object
	    QGeoPositionInfoSource* positionSource() const;


	    // This method is called to stop the retrieval of location information
	    Q_INVOKABLE void stopUpdates();



	    double latitude() const;
	    double longitude() const;



Q_SIGNALS:
	    // The change notification signals of the properties
	    void dataChanged();



private Q_SLOTS:
	void positionUpdated(const QGeoPositionInfo & pos);







private:
	QGeoPositionInfoSource *m_positionSource;
	double m_latitude;
	double m_longitude;
};
#endif /* GPSHANDLER_H_ */

 in main.cpp

 

    qmlRegisterType<GPShandler>();
    
    GPShandler* test=new GPShandler(&app);
    test->positionSource()->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(&app);

    qml->setContextProperty("_location", test);

 In main.qml this function startNav() is trigerred on button click.

 

function sendCoordinates(lat,lon)
        {
            var l = (lat) + "," + (lon)
            cleaningSearcher.navCode = l //passing data in this format: xxxxxx,xxxxxxx which is then parsed in c++, this part works ok
            showListViewAnimation.play()
            }
        

        
        function startNav()
        {
            _location.requestUpdate()
            
            onDataChanged: {
                
                console.log("COORDINATE-==============")
                console.log(_location.latitude) // ALWAYS RETURN 0 ?????
                console.log(_location.longitude)
                console.log("COORDINATE-==============")
                root.sendCoordinates(_location.latitude,_location.longitude)
            
            }
        }

 

 

But these always return 0 on simulator, permissions are set, location services are on.  I have no idea where to look anymore :smileysad:

 

_location.latitude and _location.longitude
Developer
RileyGB
Posts: 284
Registered: ‎08-06-2010
My Device: Z10

Re: What's the problem with this location handler ?

It seems that Location services degraded significantly in Beta 4. There's likely nothing wrong with your code. Check out this thread http://supportforums.blackberry.com/t5/Cascades-Development/LocationDiagnostics/m-p/2020855#M7742



Follow me on twitter @RileyGB - https://twitter.com/RileyGB
View my BB10 OpenSource projects - https://github.com/RileyGB/BlackBerry10-Samples
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

I don't have Dev Alpha, only simulator. The problem is it always returns 0 in qml. I tried with locadiondiagnostics sample, took the whole code, implemented it in my qml code in same way they implemented it in the sample, console log returns corrects values from parser but in my qml code values returned are always 0.

Either I'm doing something wrong with exposing c++ values to qml, or something is wrong with the beta 4 sdk.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10

Re: What's the problem with this location handler ?

I don't see the problem. Did you try initializing m_latitude and m_longitude with something other than 0 to see if they are not actually getting changed, as opposed to being determined as 0? Might give a clue.

Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

I'll try with values different than 0, but I don't think it'll solve this issue.

Also another thing, when I used the whole locationdiagnostics sample, lat and lon on c++ side returned correct values(the one provided by simulator controller) but on qml side they return 0 for both. I used same approach as shown in the sample to use c++ values in qml but no luck. And this to be more strange, locationdiagnostics sample works OK on simulator. Figure this out :smileysad:
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

Full qml

 


function sendCoordinates(lat,lon) { var l = (lat) + "," + (lon) cleaningSearcher.navCode = l showListViewAnimation.play() } function startSearch() { showListViewAnimation.play() cleaningSearcher.zipCode = zipCodeField.text } function startNav() { _location.requestUpdate() onDataChanged: { console.log("COORDINATE-==============") console.log(_location.latitude) console.log(_location.longitude) console.log("COORDINATE-==============") root.sendCoordinates(_location.latitude,_location.longitude) } } layout: DockLayout {} ImageButton { defaultImageSource: "asset:///images/getLocation.png" pressedImageSource: "asset:///images/getLocation.png" horizontalAlignment: HorizontalAlignment.Left verticalAlignment: VerticalAlignment.Bottom translationX: 5.0 translationY: -5.0 onClicked: root.startNav() }

 

On first click on the button, location returned is 0 or whatever lat and lon are initialised in constructor. On second click location is correctly returned to what is given by the simulator controller. I change location in controller to other values, click the button - location changes are not returned, returns prvious values. Click once more - location values are changed.

 

How to solve this now ?

Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

Nobody ? Seems that I must remove location feature from my app(s) for now.
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

Come on, I need this for tomorrows port-a-thon :smileyhappy:
BlackBerry Development Advisor
shaque
Posts: 237
Registered: ‎07-14-2008
My Device: Not Specified

Re: What's the problem with this location handler ?

Hello,

Does the locationdiagnostics app update the location as expected in your environment?

 

Shadid

Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: What's the problem with this location handler ?

Yep, it works fine on simulator. I run it, click start updates, page switches; first it shows empty values but after 1sec it displays relevant location data.

I'm using same approach in my code, but it's failing.