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
Contributor
dhiraj_n
Posts: 24
Registered: ‎11-11-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Getting Location of the device

[ Edited ]

I need to get get device location in latitude , longitude and then address . 

       I have gone through blackberry docs sample app for this but its very complicated . Could anyone please tell me how should I do this ? Or provide me simple code for it like just for getting latitude and longitude .

Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Getting Location of the device

[ Edited ]
Please use plain text.
Contributor
dhiraj_n
Posts: 24
Registered: ‎11-11-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Re: Getting Location of the device

Thanks Benecore,

 

I have done foloowing code

 

in constructor of .cpp file

m_positionSource = QtMobilitySubset::QGeoPositionInfoSource::createDefaultSource(this);
	    if ( m_positionSource ) {
	        // connect to the QGeoPositionInfoSource's signals, to get the position info and/or error status
	        connect(m_positionSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));
	        connect(_source, SIGNAL(updateTimeout()), this, SLOT(positionUpdateTimeout()));
	    }

 then created one methos as follow--

void ApplicationUI::positionUpdated(QGeoPositionInfo& pos)
{

	m_satelliteSource = QGeoSatelliteInfoSource::createDefaultSource(this);
m_positionSource->requestUpdate(120000); m_latitude = pos.coordinate().latitude(); m_longitude = pos.coordinate().longitude(); showToast(m_latitude); showToast(m_longitude); }

 Can this work ? 

 

 

Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Getting Location of the device

I have no experience with Geo location, because i don't used location in my apps.
But if you complied with the API should all work trouble-free



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: Getting Location of the device

[ Edited ]

Hi,

 

Though you can call requestUpdate() from within your positionUpdated() slot, to keep updates coming, you need to first call it after calling createDefaultSource() and connect(), to get updates started. You could call it in your ApplicationUI constructor, if you want to request an update right away, or call it from your main, if you need to set up other components first. But ApplicationUI:: positionUpdated() will not get triggered until either requestUpdate() or startUpdates() is called. Otherwise what you have should work.

 

Jim

 

Please use plain text.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Re: Getting Location of the device

Thanks jehrismann,  I tried whatever you told me but its still not working.   Would you please provide me sample code for it ?

Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: Getting Location of the device

Hi, 

 

How is it not working? Is either of your positionUpdated() or updateTimeout() slots getting invoked? You could check the return value from the connect() calls (should be true) to ensure the connections are valid.

 

Just to be sure, do you have the app permission for location services set in your bar-descriptor.xml file?

 

And are Location Services enabled on your device? (Settings -> Location Services)

 

 

Did you try the sample that Benecore gave the link to? (http://supportforums.blackberry.com/t5/Native-Development/Getting-the-device-s-location/m-p/2179889/...). That's about as simple as it gets, assuming you're comfortable with Qt. From that link you should be able to create a test app that has working positioning updates. Get that working and then you should be able to get positioning working in your own app.

 

Jim

Please use plain text.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Re: Getting Location of the device

[ Edited ]

I have done this ---

 

// Default empty project template
#include "LocationApp.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/system/SystemToast>


#include <QtLocationSubset/QGeoPositionInfo>
#include <QtLocationSubset/QGeoPositionInfoSource>
#include <QtLocationSubset/QGeoSatelliteInfo>
#include <QtLocationSubset/QGeoSatelliteInfoSource>


using namespace bb::cascades;
using namespace QtMobilitySubset;
using namespace bb::platform::geo;
using namespace bb::system;


LocationApp::LocationApp(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);

    source = QGeoPositionInfoSource::createDefaultSource(this);

    source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

    bool positionUpdatedConnected = connect(source,SIGNAL(positionUpdated(const QGeoPositionInfo &)), this, SLOT(positionUpdated(const QGeoPositionInfo &)));

    source->setUpdateInterval(10000);

    if(positionUpdatedConnected)
    {
    	source->startUpdates();
    }
}


void LocationApp::positionUpdated (const QGeoPositionInfo & pos)
{
	latitude = pos.coordinate().latitude();

	longitude = pos.coordinate().longitude();

}

void LocationApp::showToast(QString text) {

	bb::system::SystemToast toast;
	toast.setBody(text);
	toast.setPosition(bb::system::SystemUiPosition::MiddleCenter);
	toast.exec();

}

The posiotionUpdated() slot is getting updated. I had added app permission and enabled location servicces in device also .  Now , latitude() and longitude() method returns double variable but I want to get it in String and to show it on toast because toast accept string variable .  How can I do this ?

Please use plain text.
Developer
Benecore
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Getting Location of the device

I think better will be if you read Qt (c++) basics.

QString::number(longtitude);


If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Please use plain text.
BlackBerry Development Advisor
jehrismann
Posts: 68
Registered: ‎10-15-2012
My Device: Z10
My Carrier: Telus

Re: Getting Location of the device

Hi,

 

You could call

 

    showToast( pos.coordinate().toString() );

 from positionUpdated(). QGeoCoordinate::toString() provides a nicely formatted text output of the geographic position. You can even control the formatting.

 

Jim

Please use plain text.