国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信小程序天氣預(yù)報(bào)實(shí)戰(zhàn)

這篇具有很好參考價(jià)值的文章主要介紹了微信小程序天氣預(yù)報(bào)實(shí)戰(zhàn)。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

api接口用的和風(fēng)天氣

代碼如下

//?pages/weather/weather.js

Page({

??/**

???*?頁面的初始數(shù)據(jù)

???*/

??data:?{

????apiKey:?"1f5e75b8a3f0472aaf2f618268b30b4e",

????City:?'',

????Country:'',

????locationid:"",

????latlongFlag:?false

??},

??/**

???*?生命周期函數(shù)--監(jiān)聽頁面加載

???*/

??onLoad(options)?{?

????this.checkAuth()

??},

??checkAuth(){

????//?將當(dāng)前頁面的?this?賦值給?vm,?以區(qū)別于下面回調(diào)函數(shù)中的?this?

????const?that?=?this

????wx.getSetting({

??????success(res)?{

????????console.log(res)

????????//?1.?scope.userLocation?為真,?代表用戶已經(jīng)授權(quán)

????????//第一次判斷的時(shí)候scope.userLocation為undefined,需要運(yùn)行一次wx.getLocation才可以設(shè)置位置允許

????????if?((typeof?(res.authSetting['scope.userLocation'])?==?"undefined")?||

??????????(res.authSetting['scope.userLocation']))?{

??????????wx.getLocation({

????????????type:?'wgs84',

????????????success(res){

??????????????that.setData({

????????????????latitude:?res.latitude,

????????????????longitude:res.longitude,

????????????????latlongFlag:?true

??????????????})

??????????????console.log(res)

??????????????console.log(that.data.longitude,that.data.latitude)

??????????????that.getCityByLoaction()

????????????}

??????????})

????????}else?{

??????????//?2.?用戶未授權(quán)的情況下,?打開授權(quán)界面,?引導(dǎo)用戶授權(quán).

??????????that.requireLocation()

????????}

??????}

????})

??},

??requireLocation(){

????const?that?=?this

????wx.showModal({

??????title:?'提示',

??????content:?'需要獲取您的位置信息,請前往設(shè)置界面開啟位置權(quán)限。',

??????success:?function?(res)?{

????????if?(res.confirm)?{

??????????//?用戶點(diǎn)擊確定按鈕,打開設(shè)置界面

??????????wx.openSetting({

????????????success:?(settingRes)?=>?{

??????????????console.log("settingRes",settingRes)

??????????????if?(settingRes.authSetting['scope.userLocation'])?{

????????????????//?用戶已經(jīng)同意授權(quán)

????????????????wx.showToast({

??????????????????title:?'授權(quán)成功',

??????????????????icon:?'success',

??????????????????duration:?2000

????????????????});

????????????????that.checkAuth()

??????????????}?else?{

????????????????//?用戶依然拒絕授權(quán)

????????????????wx.showToast({

??????????????????title:?'授權(quán)失敗',

??????????????????icon:?'none',

??????????????????duration:?2000

????????????????});

??????????????}

????????????}

??????????});

????????}?else?if?(res.cancel)?{

??????????//?用戶點(diǎn)擊取消按鈕

??????????wx.showToast({

????????????title:?'您取消了授權(quán)',

????????????icon:?'none',

????????????duration:?2000

??????????});

????????}

??????}

????});

??},

??queryWeather(){

????this.weather_now()

??},

?//通過經(jīng)緯度獲取城市的id

??getCityByLoaction()?{

??????var?that?=?this

??????wx.request({

????????url:?'https://geoapi.qweather.com/v2/city/lookup?',?

????????method:?'GET',

????????data:?{

??????????key:?this.data.apiKey,

??????????location:?that.data.longitude.toString()?+?','?+?that.data.latitude.toString()

????????},

????????success:?(res)?=>?{

??????????if(res.data.code?===?"200"){

????????????this.setData({

??????????????locationid:?res.data.location[0].id,

??????????????City:res.data.location[0].name,

??????????????Country:res.data.location[0].country

????????????})

????????????//?Fetch?weather?information?using?locationid

????????????this.getWeatherInfo(this.data.locationid);

??????????}else{

????????????console.log("fail?to?input?city")

??????????}

????????},

??????})

??},

??//通過輸入城市名獲取城市的id

??weather_now(){

????wx.request({

??????url:?'https://geoapi.qweather.com/v2/city/lookup?',?

??????method:?'GET',

??????data:?{

????????key:?this.data.apiKey,

????????location:?this.data.city

??????},

??????success:?(res)?=>?{

????????if(res.data.code?===?"200"){

??????????this.setData({

????????????locationid:?res.data.location[0].id,

????????????City:res.data.location[0].name,

????????????Country:res.data.location[0].country

??????????})

??????????//?Fetch?weather?information?using?locationid

??????????this.getWeatherInfo(this.data.locationid);

????????}else{

??????????console.log("fail?to?input?city")

????????}

??????},

????});

??},

??formatTime(date)?{

????const?year?=?date.getFullYear()

????const?month?=?date.getMonth()?+?1

????const?day?=?date.getDate()

????const?hour?=?date.getHours()

????const?minute?=?date.getMinutes()

????const?second?=?date.getSeconds()

????const?weekArray?=?["周日",?"周一",?"周二",?"周三",?"周四",?"周五",?"周六"]

????const?isToday?=?date.setHours(0,?0,?0,?0)?==?new?Date().setHours(0,?0,?0,?0)

????return?{

????????hourly:?[hour,?minute].map(this.formatNumber).join(":"),

????????daily:?[month,?day].map(this.formatNumber).join("-"),

????????dailyToString:?isToday???"今天"?:?weekArray[date.getDay()]

????}

??},

??formatNumber(n)?{

????n?=?n.toString()

????return?n[1]???n?:?'0'?+?n

??},

??//?根據(jù)空氣質(zhì)量值返回對應(yīng)的顏色類

??getAqiCategory(value)?{

????//?根據(jù)實(shí)際情況定義不同的空氣質(zhì)量范圍

????if?(value?<=?50)?{

??????return?'good';

????}?else?if?(value?<=?100)?{

??????return?'moderate';

????}?else?if?(value?<=?150)?{

??????return?'unhealthy';

????}?else?{

??????return?'severe';

????}

??},

????//?獲取天氣信息的方法

????getWeatherInfo(locationid)?{

??????const?that?=?this

??????wx.request({

????????url:?`https://devapi.qweather.com/v7/weather/now?location=${locationid}&key=${that.data.apiKey}`,

????????method:?'GET',

????????success:?(res)?=>?{

??????????if(res.data.code?===?"200"){

????????????that.setData({

??????????????now:?res.data.now

????????????})

??????????}

??????????//?Handle?the?weather?information?response

??????????console.log('Weather?Now:',?res.data);

????????},

????????fail:?(error)?=>?{

??????????//?Handle?the?request?failure

??????????console.error('Failed?to?fetch?weather?information:',?error);

????????}

??????});

??????wx.request({

????????url:?`https://devapi.qweather.com/v7/weather/24h?location=${locationid}&key=${that.data.apiKey}`,

????????method:?'GET',

????????success:?(res)?=>?{

??????????if(res.data.code?===?"200"){

????????????res.data.hourly.forEach(function(item){

????????????????item.time?=?that.formatTime(new?Date(item.fxTime)).hourly

????????????})

????????????that.setData({

??????????????hourly:?res.data.hourly

????????????})

??????????}

??????????//?Handle?the?weather?information?response

??????????console.log('Weather?24?hour:',?res.data);

????????},

????????fail:?(error)?=>?{

??????????//?Handle?the?request?failure

??????????console.error('Failed?to?fetch?weather?information:',?error);

????????}

??????});

??????wx.request({

????????url:?`https://devapi.qweather.com/v7/weather/7d?location=${locationid}&key=${that.data.apiKey}`,

????????method:?'GET',

????????success:?(res)?=>?{

??????????if(res.data.code?===?"200"){

????????????that.setData({

??????????????daily:?res.data.daily

????????????})

??????????}

??????????//?Handle?the?weather?information?response

??????????console.log('Weather?7d:',?res.data);

????????},

????????fail:?(error)?=>?{

??????????//?Handle?the?request?failure

??????????console.error('Failed?to?fetch?weather?information:',?error);

????????}

??????});

??????wx.request({

????????url:?`https://devapi.qweather.com/airquality/v1/now/${locationid}?key=${that.data.apiKey}`,

????????method:?'GET',

????????success:?(res)?=>?{

??????????console.log('Aqi?Information:',?res.data);

??????????if(res.data.code?===?"200"){

????????????that.setData({

??????????????aqiAvailable:true,

??????????????aqi:?res.data.aqi[0],

??????????????aqicolor?:?this.getAqiCategory(res.data.aqi[0].value)

????????????})

??????????}else{

????????????that.setData({

??????????????aqiAvailable:false

????????????})

??????????}

????????},

????????fail:?(error)?=>?{

??????????//?Handle?the?request?failure

??????????console.error('Failed?to?fetch?aqi?information:',?error);

????????}

??????});

????},

??//獲取輸入框的值

??getInutValue(e)?{

????console.log(e);

????this.setData({

??????city:?e.detail.value??//獲取頁面input輸入框輸入的值,并傳給city

????})

????console.log(this.data.city);

??},

??/**

???*?生命周期函數(shù)--監(jiān)聽頁面初次渲染完成

???*/

??onReady()?{

??},

??/**

???*?生命周期函數(shù)--監(jiān)聽頁面顯示

???*/

??onShow()?{

??},

??/**

???*?生命周期函數(shù)--監(jiān)聽頁面隱藏

???*/

??onHide()?{

??},

??/**

???*?生命周期函數(shù)--監(jiān)聽頁面卸載

???*/

??onUnload()?{

??},

??/**

???*?頁面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動作

???*/

??onPullDownRefresh()?{

??},

??/**

???*?頁面上拉觸底事件的處理函數(shù)

???*/

??onReachBottom()?{

??},

??/**

???*?用戶點(diǎn)擊右上角分享

???*/

??onShareAppMessage()?{

??}

??

})文章來源地址http://www.zghlxwxcb.cn/news/detail-825373.html

到了這里,關(guān)于微信小程序天氣預(yù)報(bào)實(shí)戰(zhàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 微信小程序基于和風(fēng)天氣的天氣預(yù)報(bào)(自動和手動定位)

    微信小程序基于和風(fēng)天氣的天氣預(yù)報(bào)(自動和手動定位)

    目錄 ? ? ? ?前言 ? ? 效果圖 ? ? ? ? ? 和風(fēng)天氣API獲取 ? ? ? ? ? ? ? ? ?微信小程序后臺配置域名 ? ? ? ? ? ? 選擇城市彈窗 ? ? ? 頁面代碼 注意事項(xiàng)(謹(jǐn)記) 最近在開發(fā)小程序,將自己寫的分享給大家,希望能幫助到你們! ? 網(wǎng)址鏈接:dev.qweather.com 我用的是和風(fēng)天

    2024年02月11日
    瀏覽(22)
  • Flutter開發(fā)微信小程序?qū)崙?zhàn):構(gòu)建一個(gè)簡單的天氣預(yù)報(bào)小程序

    Flutter開發(fā)微信小程序?qū)崙?zhàn):構(gòu)建一個(gè)簡單的天氣預(yù)報(bào)小程序

    微信小程序是一種快速、高效的開發(fā)方式,F(xiàn)lutter則是一款強(qiáng)大的跨平臺開發(fā)框架。結(jié)合二者,可以輕松地開發(fā)出功能豐富、用戶體驗(yàn)良好的微信小程序。 這里將介紹如何使用Flutter開發(fā)一個(gè)簡單的天氣預(yù)報(bào)小程序,并提供相應(yīng)的代碼示例。 在開始之前,確保你已經(jīng)安裝了Fl

    2024年02月12日
    瀏覽(31)
  • 微信小程序開發(fā)--利用和風(fēng)天氣API實(shí)現(xiàn)天氣預(yù)報(bào)小程序

    本來是參照《微信小程序開發(fā)實(shí)戰(zhàn)》做一個(gè)天氣預(yù)報(bào)小程序的,實(shí)際運(yùn)行的時(shí)候提示錯(cuò)誤,code 400,參數(shù)錯(cuò)誤。說明問題應(yīng)該出在查詢API的語句上,沒有返回結(jié)果。 查閱后才知道,可能書籍出版時(shí)間較早,現(xiàn)在的和風(fēng)獲取天氣的API出現(xiàn)了一些調(diào)整,具體見實(shí)時(shí)天氣 for API | 和

    2023年04月27日
    瀏覽(30)
  • 【小程序】微信開發(fā)者工具+心知天氣API實(shí)現(xiàn)天氣預(yù)報(bào)

    【小程序】微信開發(fā)者工具+心知天氣API實(shí)現(xiàn)天氣預(yù)報(bào)

    問:為什么使用心知天氣的天氣數(shù)據(jù)API而不是其他產(chǎn)品? 答: 心知天氣為我們提供了一款通過標(biāo)準(zhǔn)的Restful API接口進(jìn)行數(shù)據(jù)訪問的天氣數(shù)據(jù)API產(chǎn)品; 心智天氣官網(wǎng)為我們提供了足夠詳細(xì)的開發(fā)文檔和用戶手冊,方便我們快速上手進(jìn)行開發(fā); 心知天氣旗下的天氣數(shù)據(jù)API針對不

    2024年01月16日
    瀏覽(35)
  • 天氣預(yù)報(bào)小程序的設(shè)計(jì)與實(shí)現(xiàn)

    天氣預(yù)報(bào)小程序的設(shè)計(jì)與實(shí)現(xiàn)

    實(shí)驗(yàn)?zāi)康?1、 天氣預(yù)報(bào) 項(xiàng)目的設(shè)計(jì)與實(shí)現(xiàn); 實(shí)驗(yàn)環(huán)境 個(gè)人手機(jī)、與因特網(wǎng)連接的計(jì)算機(jī)網(wǎng)絡(luò)系統(tǒng);主機(jī)操作系統(tǒng)為Windows或MAC;微信開發(fā)者工具、IE等軟件。 數(shù)據(jù)支持: 進(jìn)制數(shù)據(jù)天氣預(yù)報(bào)api ? 騰訊地圖逆地址解析: ? 實(shí)驗(yàn) 項(xiàng)目需求 獲取用戶位置權(quán)限 獲取當(dāng)前位置 根據(jù)當(dāng)

    2024年02月10日
    瀏覽(21)
  • 面對洪水困境,如何利用Python編寫天氣預(yù)報(bào)程序?

    洪水是一種自然災(zāi)害,給人們的生活和財(cái)產(chǎn)帶來極大的威脅。在遭遇洪災(zāi)時(shí),及時(shí)了解天氣預(yù)報(bào)成為保護(hù)自身安全的關(guān)鍵。而如何利用Python編寫一個(gè)簡單但功能強(qiáng)大的天氣預(yù)報(bào)程序,為我們提供準(zhǔn)確的天氣信息呢?本文將介紹一種方法來實(shí)現(xiàn)這一目標(biāo)。 首先,我們需要安裝一

    2024年02月14日
    瀏覽(27)
  • ESP8266獲取天氣預(yù)報(bào)信息,并使用CJSON解析天氣預(yù)報(bào)數(shù)據(jù)

    ESP8266獲取天氣預(yù)報(bào)信息,并使用CJSON解析天氣預(yù)報(bào)數(shù)據(jù)

    當(dāng)前文章介紹如何使用ESP8266和STM32微控制器,搭配OLED顯示屏,制作一個(gè)能夠?qū)崟r(shí)顯示天氣預(yù)報(bào)的智能設(shè)備。將使用心知天氣API來獲取天氣數(shù)據(jù),并使用MQTT協(xié)議將數(shù)據(jù)傳遞給STM32控制器,最終在OLED顯示屏上顯示。 心知天氣是一家專業(yè)的氣象數(shù)據(jù)服務(wù)提供商,致力于為全球用戶

    2024年02月10日
    瀏覽(64)
  • Android制作天氣預(yù)報(bào)軟件 —— 天氣查詢

    Android制作天氣預(yù)報(bào)軟件 —— 天氣查詢

    天氣查詢功能包括信息顯示和地區(qū)選擇兩個(gè)版塊,二者均通過調(diào)用極速數(shù)據(jù)的相關(guān)接口進(jìn)行實(shí)現(xiàn)。其中,信息顯示界面作為軟件首頁,默認(rèn)先顯示系統(tǒng)設(shè)置的地區(qū)天氣情況,用戶可通過地區(qū)選擇的界面進(jìn)行修改信息。對于天氣信息,受接口調(diào)用次數(shù)限制,系統(tǒng)設(shè)置每24小時(shí)更

    2024年02月12日
    瀏覽(25)
  • 【小項(xiàng)目】微信定時(shí)推送天氣預(yù)報(bào)Github項(xiàng)目使用及原理介紹-包含cron、天氣預(yù)報(bào)、常用api...

    【小項(xiàng)目】微信定時(shí)推送天氣預(yù)報(bào)Github項(xiàng)目使用及原理介紹-包含cron、天氣預(yù)報(bào)、常用api...

    一、資料鏈接 1、github地址 https://github.com/qq1534774766/wx-push 2、教程地址 https://blog.csdn.net/qq15347747/article/details/126521774 3、易客云API(自動發(fā)送天氣) https://yikeapi.com/account/index 4、apispace-各種接口(名人名言) https://www.apispace.com/console/api?orgId=6356 5、微信公眾平臺 https://mp.weixin.qq.com/d

    2024年02月02日
    瀏覽(34)
  • QT實(shí)現(xiàn)天氣預(yù)報(bào)

    QT實(shí)現(xiàn)天氣預(yù)報(bào)

    public: ? ? MainWindow(QWidget* parent = nullptr); ? ? ~MainWindow(); ? ?protected: 形成文本菜單來用來右鍵關(guān)閉窗口 ? ? void contextMenuEvent(QContextMenuEvent* event); 鼠標(biāo)被點(diǎn)擊之后此事件被調(diào)用 ? ? void mousePressEvent(QMouseEvent *ev); 移動窗口 ? ? void mouseMoveEvent(QMouseEvent* ev); ? ? //重寫過濾器方法

    2024年02月12日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包