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
Regular Contributor
dhirajnangare
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 ?

 

Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Regular Contributor
dhirajnangare
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 

Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Regular Contributor
dhirajnangare
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. 

Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
BBSJdev
Posts: 6,094
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.