天气 最后更新时间: 2023年03月27日
天气查询服务(AMAP.Weather)是 LBS 基础服务之一,地图 JS API 提供了两种查询服务:
- 实时天气
- 天气预报
天气预报服务提供当天至第三天的预报数据。
实时天气查询
通过城市名称、区域编码(如杭州市、330100),查询目标城市/区域的实时天气状况。
//加载天气查询插件
AMap.plugin('AMap.Weather', function() {
//创建天气查询实例
var weather = new AMap.Weather();
//执行实时天气信息查询
weather.getLive('杭州市', function(err, data) {
console.log(err, data);
});
});
实时天气查询结果说明
天气预报查询
通过城市名称、区域编码(如北京市、110000),查询目标城市/区域的天气预报状况。
//加载天气查询插件
AMap.plugin('AMap.Weather', function() {
//创建天气查询实例
var weather = new AMap.Weather();
//执行实时天气信息查询
weather.getForecast('北京市', function(err, data) {
console.log(err, data);
});
});
天气预报查询结果说明
Forcast 对象说明