为什么在使用 google 地图 API 获取坐标时收到 NULL?
我尝试使用 Google Maps API 获取特定位置的坐标,但得到的坐标为 NULL
。我能够连接到一个插槽,但是当我尝试读取回复的数据时,它返回为 NULL
(当我执行 reply->readAll()
时,它返回为 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();
}
I am trying to fetch the coordinates of a specific location using the Google Maps API, but I am getting coordinates as NULL
. I am able to connect to a slot, but when I try to read the replied data, it comes back as NULL
(When I do reply->readAll()
, it comes back as NULL).
Here is the sample code:
#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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们需要添加以下行来启用系统代理
We need to add the below line to enable system proxy