首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用来自中国的google-geocoding-api

使用来自中国的google-geocoding-api
EN

Stack Overflow用户
提问于 2016-09-30 20:17:16
回答 1查看 428关注 0票数 0

我是一个来自中国的新手程序员。我在使用google-geocoding api时遇到了一些问题,当我使用以下代码进行调试时,它是正确的,但当我在发布模式下使用生成的.exe文件编译时,没有响应。因为我在中国,所以我只能使用网络代理访问URL,所以我不知道是网络问题还是我的代码问题。有没有人可以帮我试一下下面的代码来检查这个问题。

代码语言:javascript
复制
// street_name.cpp : 
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <Windows.h>
#include <wininet.h>

using namespace std;
#define MAXBLOCKSIZE 500
#pragma comment (lib, "wininet.lib")
void download(const char*);

int main(int argc, char* argv[]){
    const char *cUrl = NULL;
    char Url[512];
    float lat = 45.798748;
    float lng = 126.531115;

    sprintf(Url,"https://maps.googleapis.com/maps/api/geocode/xml?latlng=45.797749,126.523811&result_type=route&address_component_type=route&key=AIzaSyC6M3Pbbjdrgtl8QZjuJPK-1JdAJD5oEgA",lat,lng);
    cUrl = Url;
    download(cUrl);


    if (argc > 1)
    {
        download((const char*)argv[1]);
    }
    else
    {
        cout << "Usage: auto-Update url";
    }
    return 0;
}

/**
* 
* @param Url: The target action url
*
*/
void download(const char *Url)
{
    HINTERNET hSession = InternetOpenA("RookIE/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    string StreetName;  
    if (hSession != NULL)
    {
        HINTERNET handle2 = InternetOpenUrlA(hSession, Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
        if (handle2 != NULL)
        {
            cout << Url << endl;
            byte Temp[MAXBLOCKSIZE] = {0};
            ULONG Number = 1;

            int i = 0;
            ofstream ofs("baidu.txt");
            if (ofs)
            {
                while (Number > 0)
                {
                    InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);
                    string a = string((const char*)Temp,Number);    
                    ofs << a.c_str();
                    StreetName += a;
                }
                ofs.close();
            }   
            InternetCloseHandle(handle2);
            handle2 = NULL;
        }
        InternetCloseHandle(hSession);
        hSession = NULL;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-10-05 17:51:23

如果您的请求来自中国,可能是HTTPS请求被阻止。尝试使用HTTP。

我想这可能和https://meta.stackexchange.com/questions/191338/https-problem-when-accessing-stack-overflow-in-china有关

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

https://stackoverflow.com/questions/39791353

复制
相关文章

相似问题

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