当前位置:网站首页>Unity 接入天气系统
Unity 接入天气系统
2022-07-04 03:55:00 【九本才】

我使用了高德开放平台的天气预报接口接入到Unity中。
高德开放平台 | 高德地图API高德开放平台官网https://lbs.amap.com/注册高德开放平台后,鼠标移动到右上角头像后就会发现应用管理,点击应用管理,再点击创建新应用。

点击添加,Web服务就可以使用天气的API。

创建完成后就可以看到对应的Key

然后我们查看开发文档就很容易获取到天气的数据。
天气查询API服务地址:
URL | https://restapi.amap.com/v3/weather/weatherInfo?parameters |
请求方式 | GET |
parameters代表的参数包括必填参数和可选参数。所有参数均使用和号字符(&)进行分隔。下面的列表枚举了这些参数及其使用规则。
- 请求参数
参数名 | 含义 | 规则说明 | 是否必须 | 缺省值 | |
|---|---|---|---|---|---|
key | 请求服务权限标识 | 用户在高德地图官网申请web服务API类型KEY | 必填 | 无 | |
city | 城市编码 | 输入城市的adcode,adcode信息可参考城市编码表 | 必填 | 无 | |
extensions | 气象类型 | 可选值:base/all base:返回实况天气 all:返回预报天气 | 可选 | 无 | |
output | 返回格式 | 可选值:JSON,XML | 可选 | JSON | |
下面是我获取到的数据。


注意实时天气和天气预报是两个接口。
代码示例,此代码就可以获取到天气的json数据,通过json解析就可以将获取到的数据显示在UI上了。
IEnumerator GetBase()
{
UnityWebRequest webRequest = UnityWebRequest.Get(urlBase);
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
Debug.Log(webRequest.error);
else
{
// Debug.Log(webRequest.downloadHandler.text);
}
}
边栏推荐
猜你喜欢

牛客小白月赛49

Kivy教程之 格式化文本 (教程含源码)

How to view installed r packages in R language

RPC - gRPC简单的demo - 学习/实践

Keysight n9320b RF spectrum analyzer solves tire pressure monitoring scheme

Distributed cap theory

Sample template of software design document - learning / practice

分享一些我的远程办公经验

Rhcsa 04 - process management

Annex V: briefing on the attack process docx
随机推荐
Solve the problem of failed to load property source from location 'classpathapplication YML 'problem
附件一:202x年xxx攻防演习授权委托书
leetcode:1314. Matrix area and [2D prefix and template]
[Yugong series] go teaching course 002 go language environment installation in July 2022
CRS-4013: This command is not supported in a single-node configuration.
Can closed data be deleted by DBCA? can
Kivy tutorial 07 component and attribute binding implementation button button click to modify the label component (tutorial includes source code)
Graduation project
分布式CAP理论
Sample template of software design document - learning / practice
Unity中RampTex介绍和应用: 溶解特效优化
C language one-way linked list exercise
附件2-2保密承诺书.docx
"Don't care too much about salary when looking for a job", this is the biggest lie I've ever heard
B. All Distinct
Dp83848+ network cable hot plug
Talking about what a high-quality little red book copy needs to have
优秀的测试/开发程序员是怎么修炼的?该往哪走......
附件五:攻击过程简报.docx
Correct the classpath of your application so that it contains a single, compatible version of com. go