weather

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 6 Imported by: 0

README

amap-weather

:rainbow: 基于 高德开放平台 的天气查询扩展包。

Install

$ go get -u github.com/Simoon-F/amap-weather

Configure

在使用本扩展之前,你需要去 高德开放平台 注册账号,然后创建应用,获取应用的 Web APi Key。

Use

package main

import (
	weather "github.com/Simoon-F/amap-weather"
)

w := weather.NewWeather("key")

GetLiveWeather

resp, _ := w.GetLiveWeather("中山", "json")

Example:

{
  "status":"1",
  "count":"2",
  "info":"OK",
  "infocode":"10000",
  "lives":[
    {
      "province":"辽宁",
      "city":"中山区",
      "adcode":"210202",
      "weather":"晴",
      "temperature":"30",
      "winddirection":"西",
      "windpower":"≤3",
      "humidity":"32",
      "reporttime":"2022-06-24 17:32:47"
    },
    {
      "province":"广东",
      "city":"中山市",
      "adcode":"442000",
      "weather":"晴",
      "temperature":"33",
      "winddirection":"西南",
      "windpower":"≤3",
      "humidity":"59",
      "reporttime":"2022-06-24 17:31:06"
    }
  ]
}

GetLiveWeather

resp, err := w.GetForecastsWeather("广州", "json")

Example:

{
  "status":"1",
  "count":"1",
  "info":"OK",
  "infocode":"10000",
  "forecasts":[
    {
      "city":"广州市",
      "adcode":"440100",
      "province":"广东",
      "reporttime":"2022-06-24 18:00:26",
      "casts":[
        {
          "date":"2022-06-24",
          "week":"5",
          "dayweather":"多云",
          "nightweather":"多云",
          "daytemp":"35",
          "nighttemp":"25",
          "daywind":"北",
          "nightwind":"北",
          "daypower":"≤3",
          "nightpower":"≤3"
        },
        {
          "date":"2022-06-25",
          "week":"6",
          "dayweather":"多云",
          "nightweather":"多云",
          "daytemp":"35",
          "nighttemp":"25",
          "daywind":"北",
          "nightwind":"北",
          "daypower":"≤3",
          "nightpower":"≤3"
        },
        {
          "date":"2022-06-26",
          "week":"7",
          "dayweather":"多云",
          "nightweather":"多云",
          "daytemp":"35",
          "nighttemp":"26",
          "daywind":"北",
          "nightwind":"北",
          "daypower":"≤3",
          "nightpower":"≤3"
        },
        {
          "date":"2022-06-27",
          "week":"1",
          "dayweather":"雷阵雨",
          "nightweather":"雷阵雨",
          "daytemp":"34",
          "nighttemp":"27",
          "daywind":"北",
          "nightwind":"北",
          "daypower":"≤3",
          "nightpower":"≤3"
        }
      ]
    }
  ]
}

Parameter Description

GetLiveWeather(city, format string)
GetForecastsWeather(city, format string)
  • $city - 城市名/高德地址位置 adcode,比如:“广州” 或者(adcode:440100);
  • $format - 输出的数据格式,当前只支持 JSON 格式

Reference

License

MIT

Documentation

Index

Constants

View Source
const Version = "0.0.2"

Version current version

Variables

This section is empty.

Functions

This section is empty.

Types

type Weather

type Weather struct {
	// contains filtered or unexported fields
}

func NewWeather

func NewWeather(key string) *Weather

func (*Weather) GetForecastsWeather added in v0.0.2

func (w *Weather) GetForecastsWeather(city, format string) (types.WeatherResponse, error)

GetForecastsWeather 获取天气预报

func (*Weather) GetLiveWeather added in v0.0.2

func (w *Weather) GetLiveWeather(city, format string) (types.WeatherResponse, error)

GetLiveWeather 获取实时天气

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL