为什么在使用 google 地图 API 获取坐标时收到 NULL?

发布于 2024-11-08 03:01:04 字数 1073 浏览 2 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花开柳相依 2024-11-15 03:01:04

我们需要添加以下行来启用系统代理

  QNetworkProxyFactory::setUseSystemConfiguration(true);

We need to add the below line to enable system proxy

  QNetworkProxyFactory::setUseSystemConfiguration(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文