0
我試圖使用Google Maps API獲取特定位置的座標,但我得到的座標爲NULL
。我能夠連接到一個插槽,但是當我嘗試讀取答覆的數據時,它會回到NULL
(當我做reply->readAll()
時,它返回爲NULL)。爲什麼我在使用google maps API獲取座標時收到NULL?
下面是示例代碼:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
manager = new QNetworkAccessManager(this);
bool val = connect(manager, SIGNAL(finished (QNetworkReply *)), this,
SLOT (finished(QNetworkReply *)));
QUrl request("http://maps.google.com/maps/geo");
request.addQueryItem("q", "New York");
request.addQueryItem("sensor", false);
request.addQueryItem("output", "csv");
request.addQueryItem("key","ABQIAAAAEeYlVIrQ3v9fkg9uOreI8RQG9ySifjUFt_tfsIL5mrcfjg4w7xREocRv0kD1cjJ893_O8Jqfhe4YMA");
manager->get(QNetworkRequest(request));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::finished(QNetworkReply *reply)
{
QString replyStr = reply->readAll();
}
請'reply->錯誤()'和'reply-> Errorstring,則()'。告訴我們你遇到了什麼錯誤。 – Mat 2011-05-18 05:28:05
嗨,它說「主機maps.google.com找不到」..我們現在需要做什麼? – Naruto 2011-05-18 06:51:34
運行的代碼是什麼樣的設備?它有互聯網接入嗎?它的DNS設置是否正確? – Mat 2011-05-18 06:53:27