0

I am developing one app in BlackBerry 10 in which I need to get device location in latitude, longitude and then want to get address .I have gone through blackberry docs sample app 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 .

BB10
  • 9
  • 2

1 Answers1

0

Check below code.

void App::positionUpdated(QGeoPositionInfo geoPositionInfo) {

    if (geoPositionInfo.isValid()) {
        // We've got the position. No need to continue the listening.
        locationDataSource->stopUpdates();

        // Save the position information into a member variable
        myPositionInfo = geoPositionInfo;

        // Get the current location as latitude and longitude
        QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
        qreal latitude = geoCoordinate.latitude();
        qreal longitude = geoCoordinate.longitude();

        qDebug()<< QString("Latitude: %1 Longitude: %2").arg(latitude).arg(longitude);



    }

}

void App::startGPS() {

    qDebug() << " << starting GPS >>";

    // Obtain the location data source if it is not obtained already
    if (!locationDataSource) {
        locationDataSource = QGeoPositionInfoSource::createDefaultSource(this);
        // Whenever the location data source signals that the current
        // position is updated, the positionUpdated function is called
        connect(locationDataSource, SIGNAL(positionUpdated(QGeoPositionInfo)),this, SLOT(positionUpdated(QGeoPositionInfo)));

        // Start listening for position updates
        locationDataSource->startUpdates();
    }
}

Just call startGPS() method in your default constructor class.

For more information you can go here.

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133