利用libcurl 抓取google影像瓦片

libcurl

   libcurl主要功能就是用不同的协议连接和沟通不同的服务器~也就是相当封装了的sockPHP 支持libcurl(允许你用不同的协议连接和沟通不同的服务器)。, libcurl当前支持http, https, ftp, gopher, telnet, dict, file, 和ldap 协议。libcurl同样支持HTTPS证书授权,HTTP POST, HTTP PUT, FTP 上传(当然你也可以使用PHP的ftp扩展), HTTP基本表单上传,代理,cookies,和用户认证。 官网

   函数讲解可见: http://blog.csdn.net/haihsl123456789/article/details/41147949

Google瓦片抓取

     瓦片相关信息可见:http://blog.csdn.net/mengdong_zy/article/details/50517682


实现代码如下:

 

#include <iostream>
#include <unistd.h>
#include <curl/curl.h>
#include <curl/easy.h>
using namespace std;



size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
    int written = fwrite(ptr,size,nmemb, (FILE*)stream);
    return written;
}


int main(void)
{
    CURL *curl;
    curl_global_init(CURL_GLOBAL_ALL);
    const string url = "http://mt2.google.cn/vt/lyrs=y@258000000&hl=zh-CN&gl=CN&src=app&x=214130&y=114212&z=18";
    curl = curl_easy_init();
    FILE *fp;
    curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    if( (fp = fopen("/users/XXX/xxxx/test.jpg","ab")) == NULL )
    {
        curl_easy_cleanup(curl);
        exit(1);
    }
    
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");//这个要加不然文件传输不完全,字符串内容可自定义
    double downloadFileLenth = 0;
   
    if(CURLE_OK == curl_easy_perform(curl))
    {
        curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &downloadFileLenth);
        cout << " the file size is " <<  downloadFileLenth / 1024.0 << endl;
    }
    curl_easy_cleanup(curl);
    
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值