1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| $(function () {
| getNowArea()
| })
| /* 定位当前城市 */
| function getNowArea() {
| var nowCity = new BMap.LocalCity();
| nowCity.get(result => {
| var cityName = result.name; //当前的城市名
| console.log(cityName);
| refreshWeather(cityName);
| });
| }
| /* 获取天气信息 */
| function refreshWeather(cityName) {
| jQuery.support.cors = true;
| var url = encodeURI("http://wthrcdn.etouch.cn/weather_mini?city=" + cityName);
| //var url = "https://www.tianqiapi.com/api/?version=v6&cityid=83458415&appid=68261499&appsecret=YnD2Zs5K";
| $.ajax({
| url: url,
| type: "get",
| dataType: "json",
| async: false,
| success: function (data) {
| console.log('天气', data)
| }
| });
| }
|
|
|