OpenLayers使用2

接着上一篇https://blog.csdn.net/weixin_51416826/article/details/140161160?spm=1001.2014.3001.5502

本篇主要内容是基于高德API逆向地址解析获取城市中心点,并且设置了输入框,可以输入城市执行飞行,同时基于高德API获取城市天气信息,并显示。

逆向地址解析获得城市中心点

$.ajax({
     url:`https://restapi.amap.com/v3/geocode/geo?address=${city}&key=${key}`
}).then(res => {
     var center = res.geocodes[0].location.split(",")
     map.getView().animate({
          center: ol.proj.transform(center, 'EPSG:4326', 'EPSG:3857'),
          zoom: 10
     })
     document.getElementById('input2').value = ''
})

基于城市位置获取天气信息

$.ajax({
    url:`https://restapi.amap.com/v3/weather/weatherInfo?city=${city}&key=${key}`
}).then(res => {
    var {city, weather, temperature, winddirection, windpower} = res.lives[0]
    weather = {
              city: {val: city, name: "城市"},
              weather: {val: weather, name: "天气"},
              temperature: {val: temperature, name: "气温"},
              winddirection: {val: winddirection, name: "风向"},
              windpower: {val: windpower, name: "风速"}
            }
            
            
     for ( let key in weather){
         var template = `<tr>
             <td>${weather[key].name}</td>
             <td>${weather[key].val}</td>
           </tr>`
         $('.weather').append(template)
     }
})

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值