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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Regular Contributor
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Reverse Geocoding in BlackBerry10

Hi ,

  

    I want to do reverse geocoding for lat,long values of device which I am getting . I have done following code in my application - 

 

source = QGeoPositionInfoSource::createDefaultSource(this);

	    source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);

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

	    source->setUpdateInterval(180000);

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

 Above code is in constructor of .cpp file

 

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

	latitude = pos.coordinate().latitude();

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

	QGeoCoordinate GCoor(latitude,longitude);


		//GCoor.setLatitude(latitude);
		//GCoor.setLongitude(longitude);


		//Reverse GeoCoding
			QStringList serviceProviders =
					QGeoServiceProvider::availableServiceProviders();
			if (serviceProviders.size()) {
				QGeoServiceProvider *serviceProvider = new QGeoServiceProvider(
								serviceProviders.at(0));

				searchManager = serviceProvider->searchManager();
			}
				//searchManager->setProperty("boundary", "city");
				  reply = searchManager->reverseGeocode(GCoor);

				bool finished_connected = QObject::connect(reply, SIGNAL(finished()),
						this, SLOT(readReverseGeocode()));


}
 
void LocationDemo::readReverseGeocode() {

			QList<QGeoPlace> LocDetList = reply->places();
		
			QGeoPlace locDe = LocDetList.at(0);
			qDebug() << "City --> " << locDe.address().state();
			qDebug() << "Country Code --> " << locDe.address().countryCode();
			qDebug() << "Country --> " << locDe.address().country();


QString state = locDe.address().state();
QString countryCode = locDe.address().countryCode();
QString country = locDe.address().countryCode();

showToast(state);
showToast(countryCode);
showToast(country);
	reply->deleteLater();
		}

 But my application is exiting at this line in readReverseGeocode() method - 

 

			QGeoPlace locDe = LocDetList.at(0);

 Could anyone please tell me why is this happening ?

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

What's the error message you are getting?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

You should really put a check for the size of a list before trying to access, does it return a size() > 0?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

[ Edited ]

Also how are you defining your reply object?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Re: Reverse Geocoding in BlackBerry10

  Thanks BBSJdev for your reply .

            I am not getting the error. Application is running but at runtime when control comes at that line , application is exiting. 

Defined reply object in header file as 

QGeoSearchReply *reply

and which list are you talking about for checking the size 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

I would do several checks on this line...

 

QList<QGeoPlace> LocDetList = reply->places();

 

Make sure reply is a valid object (i.e. not null) and check the size() of LocDetList.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10
My Carrier: BlackBerry

Re: Reverse Geocoding in BlackBerry10

I tried to check size by this - 

 

if( 0 < LocDetList.size())
			{
				showToast("size greater than 0");
			}

 but not showing toast. 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

Okay then so you have found the source of your crash and now need to work back to see why you are not getting a list of locations.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reverse Geocoding in BlackBerry10

BTW it's easier to check things using debug lines, read this for help on how to do this...

http://developer.blackberry.com/native/documentation/cascades/getting_started/tools/debugging.html
http://developer.blackberry.com/native/reference/cascades/debug.html


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.