Logo
Section 1 / 2

获取位置列表

学习如何获取全球顶级城市列表以及给定区域内的国家列表。

导入

获取位置列表

学习如何获取全球顶级城市列表以及给定区域内的国家列表。

1http://dataservice.accuweather.com/locations/v1/topcities/{group}

参数类型分类描述
API_KEYstring必需这是我们的API密钥。这是一个查询参数。
groupinteger必需这是要获取的城市数量。允许的值为 50、100 和 150。这是一个路径参数。
languagestring可选返回结果的语言。默认值为 en-us。这是一个查询参数。
detailsboolean可选设置为 true 以在响应中包含完整详情,否则设置为 false。默认值为 false。这是一个查询参数。
1// 导入库 2import fetch from "node-fetch"; 3 4// 定义API密钥 5const API_KEY = '{{API_KEY}}'; 6 7// 定义路径参数 8const group = 50; 9 10// 定义端点URL 11const url = new URL(`http://dataservice.accuweather.com/locations/v1/topcities/${group}`); 12 13// 定义头部参数 14const headerParameters = { 15 contentType: 'application/json', 16}; 17 18// 定义查询参数 19const queryParameters = new URLSearchParams({ 20 apikey: API_KEY, 21}); 22 23// 设置API调用选项 24const options = { 25 method: 'GET', 26 headers: headerParameters, 27}; 28 29// 函数用于发起API调用 30async function getTopCities() { 31 try { 32 url.search = queryParameters; 33 const response = await fetch(url, options); 34 35 // 自定义函数用于打印API响应 36 printResponse(response); 37 } catch (error) { 38 // 自定义函数用于打印错误信息 39 printError(error); 40 } 41} 42 43// 调用函数发起API调用 44getTopCities();

参数类型描述
Keystring这是城市的唯一位置键。
Rankinteger这是根据人口、政治重要性和地理规模确定的排名。
LocalizedNamestring这是请求语言下的地点名称。默认语言为 en-us。
Countryobject包含城市所属国家的信息,包括国家代码、本地化名称和英文名称。
Timezoneobject包含城市指定时区的信息。
Geopositionobject包含城市地理坐标的详细信息。
1http://dataservice.accuweather.com/locations/v1/countries/{regionCode}

参数类型分类描述
API_KEYstring必需这是我们的API密钥。这是一个查询参数。
regionCodestring必需指定要获取所有国家的区域。允许的值:ASI、MEA、EUR、AFR、OCN、NAM、CAC、SAM、ARC、ANT。这是一个路径参数。
languagestring可选返回结果的语言。默认值为 en-us。这是一个查询参数。
1// 导入库 2import fetch from "node-fetch"; 3 4// 定义API密钥 5const API_KEY = '{{API_KEY}}'; 6 7// 定义路径参数 8const regionCode = 'NAM'; 9 10// 定义端点URL 11const url = new URL(`https://dataservice.accuweather.com/locations/v1/countries/${regionCode}`); 12 13// 定义头部参数 14const headerParameters = { 15 contentType: 'application/json', 16}; 17 18// 定义查询参数 19const queryParameters = new URLSearchParams({ 20 apikey: API_KEY, 21}); 22 23// 设置API调用选项 24const options = { 25 method: 'GET', 26 headers: headerParameters, 27}; 28 29// 函数用于发起API调用 30async function getCountries() { 31 try { 32 url.search = queryParameters; 33 const response = await fetch(url, options); 34 35 // 自定义函数用于打印API响应 36 printResponse(response); 37 } catch (error) { 38 // 自定义函数用于打印错误信息 39 printError(error); 40 } 41} 42 43// 调用函数发起API调用 44getCountries();

参数类型描述
IDstring这是唯一的ISO国家代码。
LocalizedNamestring这是国家在本地语言中的名称。默认语言为 en-us。
EnglishNamestring这是国家的英文名称。

简介

文本搜索