我想用C++对地址进行地理编码,并想使用QtLocation和to定位之类的东西。我认为第一步是创建一个QGeoAddress。但这是行不通的。我收到一个LNK2019失败。如果你能帮我,那就太好了!
#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;
}错误消息是(很抱歉它是德语的):
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发布于 2016-04-29 18:53:35
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,编译并使用它。
https://stackoverflow.com/questions/36936192
复制相似问题