C++ 在BLACKbERRY 10中获取设备位置
我正在BlackBerry 10中开发一个应用程序,其中我需要获取设备在纬度、经度上的位置,然后想要获取地址。我已经浏览了BlackBerry docs示例应用程序,但它非常复杂。谁能告诉我该怎么做? 或者为我提供简单的代码,就像获取纬度和经度一样。检查下面的代码C++ 在BLACKbERRY 10中获取设备位置,c++,qt,blackberry-10,blackberry-cascades,C++,Qt,Blackberry 10,Blackberry Cascades,我正在BlackBerry 10中开发一个应用程序,其中我需要获取设备在纬度、经度上的位置,然后想要获取地址。我已经浏览了BlackBerry docs示例应用程序,但它非常复杂。谁能告诉我该怎么做? 或者为我提供简单的代码,就像获取纬度和经度一样。检查下面的代码 void App::positionUpdated(QGeoPositionInfo geoPositionInfo) { if (geoPositionInfo.isValid()) { // We've
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();
}
}
void应用程序::位置已更新(QGeoPositionInfo geoPositionInfo){
if(geoPositionInfo.isValid()){
//我们已经找到位置了,不用继续听了。
locationDataSource->stopUpdates();
//将位置信息保存到成员变量中
myPositionInfo=地理位置信息;
//获取当前位置作为纬度和经度
QGeoCoordinate geoCoordinate=geoPositionInfo.coordinate();
qreal纬度=地理坐标。纬度();
qreal longitude=地理坐标。经度();
qDebug()启动日期();
}
}
只需在默认构造函数类中调用startGPS()方法
有关更多信息,请访问