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

Re: ReverseGeocoding in BlackBerry 10

then how should I do this . I mean where should it be placed?

Please use plain text.
BlackBerry Development Advisor
Kareem_ELSayed
Posts: 81
Registered: ‎09-09-2013
My Device: BlackBerry Z10

Re: ReverseGeocoding in BlackBerry 10

[ Edited ]

Not sure what's the problem, maybe no addresses returned for the points you provided in the search but will it be possible to share your code here so we can see it there is any problem?

 

also How are you testing? on device or simulator? 


Thanks,
Kareem.

Kareem ELSayed | Application Development Consultant | Developer Relations | BlackBerry | Twitter:@kemobyte
Please use plain text.
BlackBerry Development Advisor
Kareem_ELSayed
Posts: 81
Registered: ‎09-09-2013
My Device: BlackBerry Z10

Re: ReverseGeocoding in BlackBerry 10

Just tested the code with
QGeoCoordinate MakkahLoc(21.4225, 39.8261);

getting this:

City --> ""
Country Code --> "SAU"
Country --> "Saudi Arabia"

Thanks,
Kareem.
Kareem ELSayed | Application Development Consultant | Developer Relations | BlackBerry | Twitter:@kemobyte
Please use plain text.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: ReverseGeocoding in BlackBerry 10

Thanks Kareem_ELSayed for your reply . Obviously I am testing it on device and I tried with giving hardcoded points also but still application is exiting at that line. Here is my code -  

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();
		}

 

Thanks,

Dhiraj

Please use plain text.
BlackBerry Development Advisor
Kareem_ELSayed
Posts: 81
Registered: ‎09-09-2013
My Device: BlackBerry Z10

Re: ReverseGeocoding in BlackBerry 10

Are you getting values for pos.coordinate()? Not null/empty?
Kareem ELSayed | Application Development Consultant | Developer Relations | BlackBerry | Twitter:@kemobyte
Please use plain text.
Regular Contributor
dhirajnangare
Posts: 93
Registered: ‎08-20-2013
My Device: BB 10 -BlackBerry Z10

Re: ReverseGeocoding in BlackBerry 10

Yes I am getting both values. I had shown it on toast. 

Please use plain text.
New Contributor
whiteshark_it
Posts: 6
Registered: ‎09-26-2008
My Device: BlackBerry Z10 LE

Re: ReverseGeocoding in BlackBerry 10

This is the solution to reverse geocoding:

 

File .hpp

 

...
...

    Q_INVOKABLE void getReverseGeocoding(double lat, double lon);

private Q_SLOTS:

	void readReverseGeocode();
	void reverseGeocodeError(QtMobilitySubset::QGeoSearchReply::Error error, QString errorString);

private:
	bb::cascades::maps::MapView* mapView;
	bb::platform::geo::GeoLocation* deviceLocation;

	bb::cascades::Label *labelDebug;
	QtMobilitySubset::QGeoServiceProvider* serviceProvider;
	QtMobilitySubset::QGeoSearchManager* searchManager;
	QtMobilitySubset::QGeoSearchReply *reply;
...
...

 

application class .cpp

...
...
void HelpMe::getReverseGeocoding(double lat, double lon) {
	// Initialize QGeoSearchManager
	QStringList serviceProviders =
			QtMobilitySubset::QGeoServiceProvider::availableServiceProviders();

	if ( serviceProviders.size() ) {
	    serviceProvider = new QtMobilitySubset::QGeoServiceProvider(
	                      serviceProviders.at(0) );
	    searchManager = serviceProvider->searchManager();
	}

	// create GeoCoordinate from latitude and longitude
	QtMobilitySubset::QGeoCoordinate myCoord =  QtMobilitySubset::QGeoCoordinate(lat,lon);

	// get reverseGeocode
	reply = searchManager->reverseGeocode(myCoord);

	// connect signal & slot
	QObject::connect(reply,
	     SIGNAL(finished()),
	     this,
	     SLOT(readReverseGeocode()));
	QObject::connect(reply,
	     SIGNAL(error(QGeoSearchReply::Error, QString)),
	     this,
	     SLOT(reverseGeocodeError(QtMobilitySubset::QGeoSearchReply::Error, QString)));
}

void HelpMe::readReverseGeocode(){

    if (reply->error() != QtMobilitySubset::QGeoSearchReply::NoError) {
        return;
    }
    QList<QtMobilitySubset::QGeoPlace> places = reply->places();
    if (places.length() == 0)
    {
    	labelDebug->setText("Address not found!!!");
    }
    else
    {
    	QtMobilitySubset::QGeoAddress address = places[0].address();
        QString message =  address.street() + " - " + address.postcode() + " " + address.state() + " " + address.city() + ", " + address.country().toLower();
        labelDebug->setText(message);
    }
    disconnect(reply, SIGNAL(finished()), this,SLOT(readReverseGeocode()));
    disconnect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(reverseGeocodeError(QtMobilitySubset::QGeoSearchReply::Error, QString)));

    delete reply;
}

void HelpMe::reverseGeocodeError(QtMobilitySubset::QGeoSearchReply::Error error, QString errorString){
	labelDebug->setText("ERROR!!!!");
    disconnect(reply, SIGNAL(finished()), this,SLOT(readReverseGeocode()));
    disconnect(reply,SIGNAL(error(QGeoSearchReply::Error, QString)), this,SLOT(reverseGeocodeError(QtMobilitySubset::QGeoSearchReply::Error, QString)));
    reply->deleteLater();
    delete reply;
}
...
...

 

Nicola D'Amico

Italian BlackBerry Developer

Whiteshark Labs - Italy
Please use plain text.