获取地址和天气
主要提供简单的 大洲 国家城市的联动,以及IP 坐标查询,以及后续的天气继承操作
引入和简单使用
引入
npm i node_get_location_and_weather
简单使用
const NodeLocationWeatherCreater = const NodeLocationWeather = // 通过综合信息查询NodeLocationWeather /**{ "Area_CN": "欧洲", "Area_EN": "Europe", "Country_CN": "捷克", "Country_EN": "Czechia", "City_CN": "恰斯拉夫", "City_EN": "Caslav", "Latitude": "49.91099", "Longitude": "15.38972", "City_ID": "CZ3078234" }*/// 通过综合信息查询天气NodeLocationWeather// 参数与 getLocation 相同 但是支持城市天气查询country_name area_name 会报错
配置
启动配置
const NodeLocationWeatherCreater = const NodeLocationWeather =
注意:geoip 默认为不开启,需要配置为true
方法参数
getLocation()
内部接受一个对象
可选为
{city_name: 中文版本世界城市名称 || 英文版本世界城市名称 }
{city_code: 城市的内部编码}
{lat:纬度,lon:经度}
{ip:xx.xx.xx.xx}
注意:开启IP查询必须打开配置中 geoip:true{country_name:中英文的国家名称,或者是ISO-3166国家简码}
返回国家的所有城市列表{area_name:'中英文大洲的名称'}
返回所有的国家列表
// 通过综合信息查询NodeLocationWeather /** 返回数据{ "Area_CN": "欧洲", "Area_EN": "Europe", "Country_CN": "捷克", "Country_EN": "Czechia", "City_CN": "恰斯拉夫", "City_EN": "Caslav", "Latitude": "49.91099", "Longitude": "15.38972", "City_ID": "CZ3078234" }*/
getWeather()
{city_name: 中文版本世界城市名称 || 英文版本世界城市名称 }
{city_code: 城市的内部编码}
{lat:纬度,lon:经度}
{ip:xx.xx.xx.xx}
注意:开启IP查询必须打开配置中 geoip:true
参数与 getLocation 相同,只支持城市天气查询,当使用country_name,area_name 参数时候会报错
// 通过综合信息查询天气NodeLocationWeather
返回的参数与具体使用的天气API 有关。
getAllCountries()
NodeLocationWeather // 获取所有的国家信息// 输出数组/**[{ "Country_CN": "阿富汗", "Country_EN": "Afghanistan", "Area_CN": "亚洲", "Area_EN": "Asia", "country_code": "AF", "phone_code": "+93" }, 其他国家... ]*/
getAllCountriesByArea()
可以使用中文
和英文
// 通过州名称获取国家信息 NodeLocationWeather // 可以使用 ‘非洲’ || Africa/*输出数组[{ "Country_CN": "阿尔及利亚", "Country_EN": "Algeria", "Area_CN": "非洲", "Area_EN": "Africa", "country_code": "DZ", "phone_code": "+213" }, 其他国家...]*/
getCitysByCountry()
可以使用参数国家中文名称
或者 国家英文名称
或者 ISO-3166-2
的国家简码
// 通过国家名称获取该国家所有城市信息NodeLocationWeather // cz || Czechia
getGeoip
获取GEOiP 对象,可以使用geoip 包的方法,例如进行内置的IP 地址包更新等等。
在服务框架中使用
安装
eggjs 中集成
// /config/config.default.js configweatherConfig = geoip: true amap: use: true country: 'CN' key: ''// 自己的key niceWind: use: true country: 'CN' key: '' type: 'lifestyle'// 自己的key openWeather: use: true key: ''// 自己的key ;// /extend/application.js'use strict';const nodeLocationAndWeather = ;const locationWeather = Symbol'Application#locationWeather';/** * 挂载获取天气的方法在app 上 初始化的时候同时初始化 */moduleexports = { thislocationWeather = ; return thislocationWeather; }; // 使用thisapplocationWeather;await thisapplocationWeather;