跳至正文
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
BG6RSH's 随记.

我们总是在感叹昨天,忽视今天,幻想着明天中渡过,且过且珍惜.....

BG6RSH's 随记.

我们总是在感叹昨天,忽视今天,幻想着明天中渡过,且过且珍惜.....

  • 首页
  • 论坛
  • 随记
  • 编程
  • 软件
  • 留言
  • 首页
  • 论坛
  • 随记
  • 编程
  • 软件
  • 留言
关

搜索

  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Subscribe
编程

利用百度地图API得到指定坐标地区的天气预报

作者 admin
2014年8月16日 1 分钟阅读
1

利用百度地图车联网API,根据经纬度/城市名查询天气的结果。源代码中要用到的一些自定义函数、结构请在本站其他代码中查找。

Delphi/Pascal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 得到坐标所在地的天气预报
function TfrmMain.GetWeather(coords: TCoordinate): WeatherResults;
var
  I, J, P, count: Integer;
  Url, PicPath: string;
  node: IXMLNode;
  XMLDoc: TXMLDocument;
  nodeList: IXMLNodeList;
  IdHTTP: TIdHTTP;
  tStream: TFileStream;
begin
  XMLDoc := TXMLDocument.Create(Self);
  IdHTTP := TIdHTTP.Create;
  try
    coords := GpsToBaiduXY(coords);
    if coords.Valid then
    begin
      Url := UrlEncode(Format(
          'http://api.map.baidu.com/telematics/v3/weather?location=%f,%f&output=xml&coord_type=wgs84&ak=A4c132a2db250e33cd1e2af37076ac28', [coords.X, coords.Y]));
      try
        XMLDoc.XML.Text := IdHTTP.Get(Url);
        XMLDoc.Active := True;
 
        node := XMLDoc.DocumentElement.ChildNodes[3]; // <results>
 
        Result.error := XMLDoc.DocumentElement.ChildValues['error'];
        Result.status := XMLDoc.DocumentElement.ChildValues['status'];
        Result.date := XMLDoc.DocumentElement.ChildValues['date'];
        Result.currentCity := node.ChildValues['currentCity'];
        Result.pm25 := node.ChildValues['pm25'];
 
        nodeList := node.ChildNodes[1].ChildNodes; // <weather_data>
 
        I := 0;
        for J := 1 to 4 do
        begin
          Result.Data[J].date := string(nodeList[I].NodeValue);
          Inc(I);
          Result.Data[J].dayPictureUrl := string(nodeList[I].NodeValue);
          Inc(I);
          Result.Data[J].nightPictureUrl := string(nodeList[I].NodeValue);
          Inc(I);
          Result.Data[J].weather := string(nodeList[I].NodeValue);
          Inc(I);
          Result.Data[J].wind := string(nodeList[I].NodeValue);
          Inc(I);
          Result.Data[J].temperature := string(nodeList[I].NodeValue);
          Inc(I);
 
          P := Pos('/images/', Result.Data[J].dayPictureUrl);
          PicPath := ExePath + copy(Result.Data[J].dayPictureUrl, P + 1,
            Length(Result.Data[J].dayPictureUrl) - P);
          PicPath := ReplaceChar(PicPath, '/', '\');
          if not FileExists(PicPath) then
          begin
            tStream := TFileStream.Create(PicPath, fmCreate);
            try
              IdHTTP.Get(Result.Data[J].dayPictureUrl, tStream); // 开始下载
            finally
              tStream.Free;
            end;
          end;
 
          P := Pos('/images/', Result.Data[J].nightPictureUrl);
          PicPath := ExePath + copy(Result.Data[J].nightPictureUrl, P + 1,
            Length(Result.Data[J].nightPictureUrl) - P);
          PicPath := ReplaceChar(PicPath, '/', '\');
          if not FileExists(PicPath) then
          begin
            tStream := TFileStream.Create(PicPath, fmCreate);
            try
              IdHTTP.Get(Result.Data[J].nightPictureUrl, tStream); // 开始下载
            finally
              tStream.Free;
            end;
          end;
        end;
      except
        abort;
      end;
    end;
  finally
    XMLDoc.Free;
    IdHTTP.Free;
  end;
end;

标签:

天气预报百度地图车联网API
作者

admin

关注我
其他文章
上一个

利用百度地图API得到指定城市的天气预报

下一个

可恨的国外免费主页空间,又关了我的网站!

一条评论
  1. Maggie说道:
    2017年1月20日 14:29

    Hi Tricia, Sorry to hear that you have been having trouble with spam… I personally have not noticed any pop-up ads on your blog… It's crazy though that people invade our privacy so easily… Beautiful sky picture… WOHBs!Wug!,!etsy

    回复

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

4条垃圾评论已被Akismet阻挡 (在新标签页中打开)

近期文章

  • www.tansoo.cn网站空间迁移至armbian主机
  • 在QT6中安装qtmqtt、qtopcua控件的方法
  • 你的 Python 环境或安装版没有 spyder‑kernels 模块或没有安装正确的版本 (>=
  • 用PYTHON爬网络小说源代码
  • QT5.15.2搭建ANDROID编译环境

近期评论

  • gg 发表在《Traccar服务软件高德地图适配版docker镜像安装教程》
  • admin 发表在《Traccar服务软件高德地图适配版docker镜像安装教程》
  • /api/positions/里addres 为什么是null啊? 发表在《Traccar服务软件高德地图适配版docker镜像安装教程》
  • gg 发表在《Traccar服务软件高德地图适配版docker镜像安装教程》
  • 9394 发表在《Traccar服务软件高德地图适配版docker镜像安装教程》

归档

  • 2025 年 6 月
  • 2023 年 6 月
  • 2022 年 10 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 6 月
  • 2019 年 11 月
  • 2019 年 8 月
  • 2019 年 6 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2017 年 9 月
  • 2016 年 7 月
  • 2016 年 5 月
  • 2015 年 12 月
  • 2015 年 4 月
  • 2015 年 1 月
  • 2014 年 12 月
  • 2014 年 11 月
  • 2014 年 10 月
  • 2014 年 9 月
  • 2014 年 8 月
  • 2014 年 7 月
  • 2014 年 6 月
  • 2014 年 5 月
  • 2013 年 10 月
  • 2013 年 9 月
  • 2013 年 8 月
  • 2013 年 7 月
  • 2013 年 6 月
  • 2013 年 5 月
  • 2013 年 4 月
  • 2013 年 3 月
  • 2013 年 2 月
  • 2013 年 1 月
  • 2012 年 12 月
  • 2012 年 11 月
  • 2012 年 10 月
  • 2012 年 6 月
  • 2012 年 3 月
  • 2011 年 8 月
  • 2011 年 5 月
  • 2011 年 4 月
  • 2011 年 3 月
  • 2011 年 1 月
  • 2010 年 8 月
  • 2010 年 6 月
  • 2010 年 4 月
  • 2010 年 3 月
  • 2010 年 2 月
  • 2010 年 1 月
  • 2009 年 12 月
  • 2009 年 11 月

分类

  • 编程
  • 软件
  • 随记

其他操作

  • 注册
  • 登录
  • 条目 feed
  • 评论 feed
  • WordPress.org

标签

aliyun Android CRC DBGridEh ddns Delphi EhLib ESP8266 GP328D gp338plus GP3688 Modbus phpbb python QT raspberry S7-SCL sapi speech SpVoice Synology traccar UART Unicode virtualbox vmware WGS84 wordpress ZeroTier 写频 动态IP 图片尺寸 地图 外挂编程 天气预报 导航 打印 扩频 拼音首字母 支票快打 树莓派 爬虫 百度地图 西门子PLC 车联网API

友情链接

  • 私有云论坛
  • 百度开放云
  • 主机管理
  • My Cloud
  • 智能家居技术论坛
  • 精灵云
  • 雅苑私站
Copyright 2026 — BG6RSH's 随记.. All rights reserved. Blogsy WordPress Theme