在 BLACKbERRY 10 中获取设备位置

Getting Device Location in BLACKbERRY 10

本文关键字:位置 获取 BLACKbERRY      更新时间:2023-10-16

>我正在 BlackBerry 10 中开发一个应用程序,我需要在纬度、经度中获取设备位置,然后想要获取地址。我已经浏览了黑莓文档示例应用程序,但它非常复杂。谁能告诉我我应该怎么做? 或者为我提供简单的代码,例如获取纬度和经度。

检查下面的代码。

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

只需在默认构造函数类中调用 startGPS() 方法即可。

有关更多信息,您可以转到此处。