首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建获取LNK2019的QGeoAddress

创建获取LNK2019的QGeoAddress
EN

Stack Overflow用户
提问于 2016-04-29 18:41:21
回答 1查看 126关注 0票数 0

我想用C++对地址进行地理编码,并想使用QtLocation和to定位之类的东西。我认为第一步是创建一个QGeoAddress。但这是行不通的。我收到一个LNK2019失败。如果你能帮我,那就太好了!

代码语言:javascript
复制
#include <QCoreApplication>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <regex>
#include <string>
#include <streambuf>
#include <QtPositioning/QGeoAddress.h>
#include <QtPositioning/QGeoLocation>
#include <QtLocation/QGeoCodingManager>
#include <QtLocation/QGeoServiceProvider>
#include <QString>
#include <QtLocation/QGeoCodeReply>

using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QGeoAddress searchAddress;
}

错误消息是(很抱歉它是德语的):

代码语言:javascript
复制
main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __cdecl QGeoAddress::QGeoAddress(void)" (__imp_??0QGeoAddress@@QEAA@XZ)" in Funktion "main".
main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""__declspec(dllimport) public: __cdecl QGeoAddress::~QGeoAddress(void)" (__imp_??1QGeoAddress@@QEAA@XZ)" in Funktion "main".
debug\Regex_GeoModA_Qt.exe : fatal error LNK1120: 2 nicht aufgelöste Externe
EN

回答 1

Stack Overflow用户

发布于 2016-04-29 18:53:35

代码语言:javascript
复制
QNetworkAccessManager* manager = new QNetworkAccessManager;

connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fReply(QNetworkReply*)));

    QString url = QString("http://maps.google.com/maps/api/geocode/json?address=%1&sensor=false&language=en").arg(your_address);

    manager->get(QNetworkRequest(QUrl(url)));





void fReply(QNetworkReply *reply)
{

    QString json = reply->readAll();
    QString strUrl = reply->url().toString();

    QJson::Parser parser;

    bool ok;

    // json is a QString containing the data to convert
    //QVariant result = parser.parse (json.toLatin1(), &ok);
    QVariant result = parser.parse (json.toLatin1(), &ok);
    if(!ok)
    {
        qDebug()<< (QString("HATA : Cannot convert to QJson object: %1").arg(json));
        return;
    }

    QString code = result.toMap()["status"].toString();
    qDebug() << "Code" << code;
    if(code != "OK")
    {
        qDebug() << (QString("HATA : Code of request is: %1").arg(code));
        return;
    }

    QVariantList results = result.toMap()["results"].toList();
    if(results.count() == 0)
    {
        qDebug() << (QString("HATA : Cannot find any locations"));
        return;
    }

    double east  = results[0].toMap()["geometry"].toMap()["location"].toMap()["lng"].toDouble();
    double north = results[0].toMap()["geometry"].toMap()["location"].toMap()["lat"].toDouble();


}

这段代码需要额外的库QJson对象。

you can download source code from here,编译并使用它。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36936192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档