Qt positioning 如何获取到城市名?



  • void MainWindow::positionUpdated(const QGeoPositionInfo &update)
    {
        ui->label_2->setText(update.coordinate().toString());
    
        QGeoLocation lo;
        lo.setCoordinate(update.coordinate());
        if (lo.isEmpty())
            qDebug() << "lo.isEmpty()" ;
        QString s = QString("国家:%1,城市:%2,县区:%3,").arg(lo.address().country()).arg(lo.address().city())
                .arg(lo.address().county());
        ui->label_3->setText(s);
    
        QGeoAddress ads = lo.address();
        if (ads.isEmpty())
            qDebug() << "ads.isEmpty()" ;
        QString s2 = QString("区:%1,state:%2,街道:%3").arg(ads.district()).arg(ads.state())
                .arg(ads.street());
        ui->label_4->setText(s2);
    
        QString s3 = QString("text: %1").arg(ads.text());
        ui->label_5->setText(s3);
    
    }
    

    能获取到经纬度,但是QGeoAddress 是空的,不知道QGeoAddress 有何存在的价值....


 

走马观花

最近的回复

关注我们

微博
QQ群











召唤伊斯特瓦尔