<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> <title>天氣預報查詢</title> <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" /> </head> <body> <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script> <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=0e0515e5982fbfb4bb949348fe907b16"></script> <script type="text/javascript"> //實時天氣 function weatherLive(city) { //加載天氣查詢插件 AMap.plugin('AMap.Weather', function() { //創建天氣查詢實例 var weather = new AMap.Weather(); //執行實時天氣信息查詢 weather.getLive(city, function(err, data) { alert("實時天氣==" + JSON.stringify(data)); return data; }); }); } //實時天氣 function weatherForecast(city) { //加載天氣查詢插件 AMap.plugin('AMap.Weather', function() { //創建天氣查詢實例 var weather = new AMap.Weather(); //執行天氣預報查詢 weather.getForecast(city, function(err, data) { alert("天氣預報==" + JSON.stringify(data)); return data; }); }); } $(document).ready(function() { weatherLive("武漢"); }) </script> </body> </html>
