geo

package
v0.0.0-...-5ed6f2c Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package geo 和风天气GeoAPI

Index

Constants

View Source
const EndPoint = "https://geoapi.qweather.com/v2/"

Variables

This section is empty.

Functions

func HitCityRequest

func HitCityRequest(para *Para, key qweather.Credential) (*http.Request, error)

HitCityRequest 热门城市查询

获取全球各国热门城市列表。

Get https://geoapi.qweather.com/v2/city/top?[请求参数]

请求参数说明:

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

range

搜索范围,可设定只在某个国家或地区范围内进行搜索,国家和地区名称需使用ISO 3166 所定义的国家代码(https://dev.qweather.com/docs/resource/glossary/#iso-3166)。如果不设置此参数,搜索范围将在所有城市。例如 range=cn

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key

func POIRangeRequest

func POIRangeRequest(para *Para, key qweather.Credential) (*http.Request, error)

POIRangeRequest POI范围搜索

提供指定区域范围内查询所有POI信息。

GET https://geoapi.qweather.com/v2/poi/range?[请求参数]

请求参数说明:

location(必选)

需要查询地区的以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)。例如 location=116.41,39.92

type(必选)

POI类型,可选择搜索某一类型的POI。
    scenic 景点
    CSTA 潮流站点
    TSTA 潮汐站点

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

radius(必选)

搜索范围,可设置搜索半径,取值范围1-50,单位:公里。**默认5公里**。

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key

func POIRangeRequestWithRequiredParam

func POIRangeRequestWithRequiredParam(location string, key qweather.Credential, t Type, radius uint16, para *Para) (*http.Request, error)

POIRangeRequestWithRequiredParam POI范围搜索 para 为其余参数,可以为 nil 详见 POIRangeRequest

func POIRequest

func POIRequest(para *Para, key qweather.Credential) (*http.Request, error)

POIRequest POI搜索

使用关键字和坐标查询POI信息(景点、火车站、飞机场、港口等)

GET https://geoapi.qweather.com/v2/poi/lookup?[请求参数]

请求参数说明:

type(必选)

POI类型,可选择搜索某一类型的POI。
    scenic 景点
    CSTA 潮流站点
    TSTA 潮汐站点

location(必选)

需要查询地区的名称,支持文字、以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)、LocationID(https://dev.qweather.com/docs/resource/glossary/#locationid)或Adcode(https://dev.qweather.com/docs/resource/glossary/#adcode)(仅限中国城市)。例如 location=北京 或 location=116.41,39.92

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

city

选择POI所在城市,可设定只搜索在特定城市内的POI信息。城市名称可以是文字或城市的LocationID。**默认不限制特定城市**。
> 城市名称为精准匹配,建议使用LocaitonID,如文字无法匹配,则数据返回为空。

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key

func POIRequestWithRequiredParam

func POIRequestWithRequiredParam(location string, key qweather.Credential, t Type, para *Para) (*http.Request, error)

POIRequestWithRequiredParam POI搜索 para 为其余参数,可以为 nil 详见 POIRequest

func SearchCityRequest

func SearchCityRequest(para *Para, key qweather.Credential) (*http.Request, error)

SearchCityRequest 城市搜索

城市搜索提供全球地理位位置、全球城市搜索服务,支持经纬度坐标反查、多语言、模糊搜索等功能。

天气数据是基于地理位置的数据,因此获取天气之前需要先知道具体的位置信息。使用城市搜索,可获取到该城市的基本信息,包括城市的Location ID(你需要这个ID去查询天气),多语言名称、经纬度、时区、海拔、Rank值、归属上级行政区域、所在行政区域等。

另外,城市搜索也可以帮助你在你的APP中实现模糊搜索,用户只需要输入1-2个字即可获得结果。

GET https://geoapi.qweather.com/v2/city/lookup?[请求参数]

请求参数说明:

location(必选)

需要查询地区的名称,支持文字、以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)、LocationID(https://dev.qweather.com/docs/resource/glossary/#locationid)或Adcode(https://dev.qweather.com/docs/resource/glossary/#adcode)(仅限中国城市)。例如 location=北京 或 location=116.41,39.92
> 模糊搜索,当location传递的为文字时,支持模糊搜索,即用户可以只输入城市名称一部分进行搜索,最少一个汉字或2个字符,结果将按照相关性和Rank值(https://dev.qweather.com/docs/resource/glossary/#rank)进行排列,便于开发或用户进行选择他们需要查看哪个城市的天气。例如location=bei,将返回与bei相关性最强的若干结果,包括黎巴嫩的贝鲁特和中国的北京市
> 重名,当location传递的为文字时,可能会出现重名的城市,例如陕西省西安市、吉林省辽源市下辖的西安区和黑龙江省牡丹江市下辖的西安区,此时会根据Rank值(https://dev.qweather.com/docs/resource/glossary/#rank)排序返回所有结果。在这种情况下,可以通过adm参数的方式进一步确定需要查询的城市或地区,例如location=西安&adm=黑龙江

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

adm

城市的上级行政区划,可设定只在某个行政区划范围内进行搜索,用于排除重名城市或对结果进行过滤。例如 adm=beijing
> 如请求参数为location=chaoyang&adm=beijing时,返回的结果只包括北京市的朝阳区,而不包括辽宁省的朝阳市

> 如请求参数仅为location=chaoyang时,返回的结果包括北京市的朝阳区、辽宁省的朝阳市以及长春市的朝阳区

range

搜索范围,可设定只在某个国家或地区范围内进行搜索,国家和地区名称需使用ISO 3166 所定义的国家代码(https://dev.qweather.com/docs/resource/glossary/#iso-3166)。如果不设置此参数,搜索范围将在所有城市。例如 range=cn

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key

func SearchCityRequestWithRequiredParam

func SearchCityRequestWithRequiredParam(location string, key qweather.Credential, para *Para) (*http.Request, error)

SearchCityRequestWithRequiredParam 城市搜索 para 为其余参数,可以为 nil 详见 SearchCityRequest

Types

type HitResponse

type HitResponse struct {
	Code        statusCode.Code `json:"code"` // 状态码
	TopCityList []struct {
		Name      string `json:"name"`      // 地区/城市名称
		Id        string `json:"id"`        // 地区/城市ID
		Lat       string `json:"lat"`       // 地区/城市纬度
		Lon       string `json:"lon"`       // 地区/城市经度
		Adm2      string `json:"adm2"`      // 地区/城市上级行政区域
		Adm1      string `json:"adm1"`      // 地区/城市所属一级行政区域
		Country   string `json:"country"`   // 地区/城市所属国家名称
		Tz        string `json:"tz"`        // 地区/城市所在时区
		UtcOffset string `json:"utcOffset"` // 地区/城市所在时区偏移小时数 参考详细说明 https://dev.qweather.com/docs/resource/glossary/#utc-offset
		IsDst     string `json:"isDst"`     // 地区/城市是否当前处于夏令时 https://dev.qweather.com/docs/resource/glossary/#daylight-saving-time 1 表示当前处于夏令时,0 表示当前不是夏令时。
		Type      string `json:"type"`      // 地区/城市的属性
		Rank      string `json:"rank"`      // 地区评分 https://dev.qweather.com/docs/resource/glossary/#rank
		FxLink    string `json:"fxLink"`    // 地区/城市对应的天气预报网页链接,便于嵌入网站或应用
	} `json:"topCityList"`
	Refer struct {
		Sources []string `json:"sources"` // 原始数据来源,**可能为空**
		License []string `json:"license"` // 数据许可或版权声明,**可能为空**
	} `json:"refer"`
}

func HitCity

func HitCity(para *Para, key qweather.Credential, client qweather.Client) (*HitResponse, error)

HitCity 热门城市查询

获取全球各国热门城市列表。

Get https://geoapi.qweather.com/v2/city/top?[请求参数]

请求参数说明:

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

range

搜索范围,可设定只在某个国家或地区范围内进行搜索,国家和地区名称需使用ISO 3166 所定义的国家代码(https://dev.qweather.com/docs/resource/glossary/#iso-3166)。如果不设置此参数,搜索范围将在所有城市。例如 range=cn

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key
client 为自定义的 Client, 若为nil, 则使用http.DefaultClient

type POIResponse

type POIResponse struct {
	Code statusCode.Code `json:"code"` // 状态码
	Poi  []struct {
		Name      string `json:"name"`      // POI(兴趣点)名称
		Id        string `json:"id"`        // POI(兴趣点)ID
		Lat       string `json:"lat"`       // POI(兴趣点)纬度
		Lon       string `json:"lon"`       // POI(兴趣点)经度
		Adm2      string `json:"adm2"`      // POI(兴趣点)上级行政区域
		Adm1      string `json:"adm1"`      // POI(兴趣点)所属一级行政区域
		Country   string `json:"country"`   // POI(兴趣点)所属国家名称
		Tz        string `json:"tz"`        // POI(兴趣点)所在时区
		UtcOffset string `json:"utcOffset"` // POI(兴趣点)所在时区偏移小时数 参考详细说明 https://dev.qweather.com/docs/resource/glossary/#utc-offset
		IsDst     string `json:"isDst"`     // POI(兴趣点)是否当前处于夏令时 https://dev.qweather.com/docs/resource/glossary/#daylight-saving-time 1 表示当前处于夏令时,0 表示当前不是夏令时。
		Type      string `json:"type"`      // POI(兴趣点)的属性
		Rank      string `json:"rank"`      // 地区评分 https://dev.qweather.com/docs/resource/glossary/#rank
		FxLink    string `json:"fxLink"`    // 该地区的天气预报网页链接,便于嵌入你的网站或应用
	} `json:"poi"`
	Refer struct {
		Sources []string `json:"sources"` // 原始数据来源,**可能为空**
		License []string `json:"license"` // 数据许可或版权声明,**可能为空**
	} `json:"refer"`
}

func POI

func POI(para *Para, key qweather.Credential, client qweather.Client) (*POIResponse, error)

POI POI搜索

使用关键字和坐标查询POI信息(景点、火车站、飞机场、港口等)

GET https://geoapi.qweather.com/v2/poi/lookup?[请求参数]

请求参数说明:

type(必选)

POI类型,可选择搜索某一类型的POI。
    scenic 景点
    CSTA 潮流站点
    TSTA 潮汐站点

location(必选)

需要查询地区的名称,支持文字、以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)、LocationID(https://dev.qweather.com/docs/resource/glossary/#locationid)或Adcode(https://dev.qweather.com/docs/resource/glossary/#adcode)(仅限中国城市)。例如 location=北京 或 location=116.41,39.92

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

city

选择POI所在城市,可设定只搜索在特定城市内的POI信息。城市名称可以是文字或城市的LocationID。**默认不限制特定城市**。
> 城市名称为精准匹配,建议使用LocaitonID,如文字无法匹配,则数据返回为空。

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key
client 为自定义的 Client, 若为nil, 则使用http.DefaultClient

func POIRange

func POIRange(para *Para, key qweather.Credential, client qweather.Client) (*POIResponse, error)

POIRange POI范围搜索

提供指定区域范围内查询所有POI信息。

GET https://geoapi.qweather.com/v2/poi/range?[请求参数]

请求参数说明:

location(必选)

需要查询地区的以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)。例如 location=116.41,39.92

type(必选)

POI类型,可选择搜索某一类型的POI。
    scenic 景点
    CSTA 潮流站点
    TSTA 潮汐站点

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

radius(必选)

搜索范围,可设置搜索半径,取值范围1-50,单位:公里。**默认5公里**。

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key
client 为自定义的 Client, 若为nil, 则使用http.DefaultClient

func POIRangeWithRequiredParam

func POIRangeWithRequiredParam(location string, key qweather.Credential, t Type, radius uint16, para *Para, client qweather.Client) (*POIResponse, error)

POIRangeWithRequiredParam POI范围搜索 para 为其余参数,可以为 nil 详见 POIRange

func POIWithRequiredParam

func POIWithRequiredParam(location string, key qweather.Credential, t Type, para *Para, client qweather.Client) (*POIResponse, error)

POIWithRequiredParam POI搜索 para 为其余参数,可以为 nil 详见 POI

type Para

type Para struct {
	Type     Type
	Radius   uint16
	Number   uint16
	Location string
	Adm      string
	Range    string
	Lang     string
	City     string
}

type SearchResponse

type SearchResponse struct {
	Code     statusCode.Code `json:"code"` // 状态码
	Location []struct {
		Name      string `json:"name"`      // 地区/城市名称
		Id        string `json:"id"`        // 地区/城市ID
		Lat       string `json:"lat"`       // 地区/城市纬度
		Lon       string `json:"lon"`       // 地区/城市经度
		Adm2      string `json:"adm2"`      // 地区/城市上级行政区域
		Adm1      string `json:"adm1"`      // 地区/城市所属一级行政区域
		Country   string `json:"country"`   // 地区/城市所属国家名称
		Tz        string `json:"tz"`        // 地区/城市所在时区
		UtcOffset string `json:"utcOffset"` // 地区/城市所在时区偏移小时数 参考详细说明 https://dev.qweather.com/docs/resource/glossary/#utc-offset
		IsDst     string `json:"isDst"`     // 地区/城市是否当前处于夏令时 https://dev.qweather.com/docs/resource/glossary/#daylight-saving-time 1 表示当前处于夏令时,0 表示当前不是夏令时。
		Type      string `json:"type"`      // 地区/城市的属性
		Rank      string `json:"rank"`      // 地区评分 https://dev.qweather.com/docs/resource/glossary/#rank
		FxLink    string `json:"fxLink"`    // 地区/城市对应的天气预报网页链接,便于嵌入网站或应用
	} `json:"location"`
	Refer struct {
		Sources []string `json:"sources"` // 原始数据来源,**可能为空**
		License []string `json:"license"` // 数据许可或版权声明,**可能为空**
	} `json:"refer"`
}

func SearchCity

func SearchCity(para *Para, key qweather.Credential, client qweather.Client) (*SearchResponse, error)

SearchCity 城市搜索

城市搜索API提供全球地理位位置、全球城市搜索服务,支持经纬度坐标反查、多语言、模糊搜索等功能。

天气数据是基于地理位置的数据,因此获取天气之前需要先知道具体的位置信息。使用城市搜索,可获取到该城市的基本信息,包括城市的Location ID(你需要这个ID去查询天气),多语言名称、经纬度、时区、海拔、Rank值、归属上级行政区域、所在行政区域等。

另外,城市搜索也可以帮助你在你的APP中实现模糊搜索,用户只需要输入1-2个字即可获得结果。

GET https://geoapi.qweather.com/v2/city/lookup?[请求参数]

请求参数说明:

location(必选)

需要查询地区的名称,支持文字、以英文逗号分隔的经度,纬度坐标(十进制,最多支持小数点后两位)(https://dev.qweather.com/docs/resource/glossary/#coordinate)、LocationID(https://dev.qweather.com/docs/resource/glossary/#locationid)或Adcode(https://dev.qweather.com/docs/resource/glossary/#adcode)(仅限中国城市)。例如 location=北京 或 location=116.41,39.92
> 模糊搜索,当location传递的为文字时,支持模糊搜索,即用户可以只输入城市名称一部分进行搜索,最少一个汉字或2个字符,结果将按照相关性和Rank值(https://dev.qweather.com/docs/resource/glossary/#rank)进行排列,便于开发或用户进行选择他们需要查看哪个城市的天气。例如location=bei,将返回与bei相关性最强的若干结果,包括黎巴嫩的贝鲁特和中国的北京市
> 重名,当location传递的为文字时,可能会出现重名的城市,例如陕西省西安市、吉林省辽源市下辖的西安区和黑龙江省牡丹江市下辖的西安区,此时会根据Rank值(https://dev.qweather.com/docs/resource/glossary/#rank)排序返回所有结果。在这种情况下,可以通过adm参数的方式进一步确定需要查询的城市或地区,例如location=西安&adm=黑龙江

key(必选)

用户认证key,请参考如何获取你的KEY(https://dev.qweather.com/docs/configuration/project-and-key/)。支持数字签名(https://dev.qweather.com/docs/resource/signature-auth/)方式进行认证。例如 key=123456789ABC

adm

城市的上级行政区划,可设定只在某个行政区划范围内进行搜索,用于排除重名城市或对结果进行过滤。例如 adm=beijing
> 如请求参数为location=chaoyang&adm=beijing时,返回的结果只包括北京市的朝阳区,而不包括辽宁省的朝阳市

> 如请求参数仅为location=chaoyang时,返回的结果包括北京市的朝阳区、辽宁省的朝阳市以及长春市的朝阳区

range

搜索范围,可设定只在某个国家或地区范围内进行搜索,国家和地区名称需使用ISO 3166 所定义的国家代码(https://dev.qweather.com/docs/resource/glossary/#iso-3166)。如果不设置此参数,搜索范围将在所有城市。例如 range=cn

number

返回结果的数量,取值范围1-20,默认返回10个结果。

lang

多语言设置,更多语言可选值参考语言代码。当数据不匹配你设置的语言时,将返回英文或其本地语言结果。

函数参数说明

para 为请求参数
key 为用户认证key
client 为自定义的 Client, 若为nil, 则使用http.DefaultClient

func SearchCityWithRequiredParam

func SearchCityWithRequiredParam(location string, key qweather.Credential, para *Para, client qweather.Client) (*SearchResponse, error)

SearchCityWithRequiredParam 城市搜索 para 为其余参数,可以为 nil 详见 SearchCity

type Type

type Type int8
const (
	Scenic Type
	CSTA
	TSTA
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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