一、根据ip获取地址
//引入搜狐API
<script typet="text/javascript" src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
//使用
console.log(returnCitySN.cname); //浙江省杭州市
console.log(JSON.stringify(returnCitySN)); //{"cip":"122.234.58.159","cid":"330100","cname":"浙江省杭州市"}
二、根据地址获取天气情况
//根据获取地址-浙江省杭州市
let reg = /.+?(省|市|区|州|盟|县|旗)/g;
let citys = returnCitySN.cname.match(reg)[1]
// 根据地址获取天气 - 本文使用Fetch发送get请求
fetch(`http://wthrcdn.etouch.cn/weather_mini?city=${citys}`)
.then(response => response.json())
.then(data =>{
A.db.weatherData = data.data.forecast[0].type
// console.log(data,data.data.forecast[0].type)
});
版权声明:本文为weixin_49521721原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。