1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
void Widget::on_pushButtonLocalisation_clicked()
{
QGeoServiceProvider qGeoService("osm");
geo = qGeoService.geocodingManager();
if (geo!=0)
{
QLocale qLocaleC(QLocale::C, QLocale::AnyCountry);
geo->setLocale(qLocaleC);
QGeoAddress qGeoAddr;
qGeoAddr.setCountry(QString::fromUtf8("France"));
qGeoAddr.setPostalCode(QString::fromUtf8("72000"));
qGeoAddr.setCity(QString::fromUtf8("Le Mans"));
connect(geo,&QGeoCodingManager::finished,this,&Widget::onFinished);
connect(geo,&QGeoCodingManager::error,this,&Widget::onError);
geo->geocode(qGeoAddr);
}
}
void Widget::onError(QGeoCodeReply *reply, QGeoCodeReply::Error error, QString errorString)
{
qDebug()<<errorString;
}
void Widget::onFinished(QGeoCodeReply *reply)
{
QList<QGeoLocation> qGeoLocs = reply->locations();
qDebug() << qGeoLocs.size() << " location(s) returned." ;
foreach (QGeoLocation qGeoLoc, qGeoLocs) {
QGeoCoordinate qGeoCoord;
qGeoCoord=qGeoLoc.coordinate();
qDebug()<< "Lat.: " << qGeoCoord.latitude() ;
qDebug()<< "Long.: " << qGeoCoord.longitude() ;
qDebug()<< "Alt.: " << qGeoCoord.altitude() ;
}
} |
Partager