国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序?qū)W習(xí)筆記之獲取位置信息操作圖文詳解

2024-07-22 01:18:54
字體:
供稿:網(wǎng)友

本文實例講述了微信小程序?qū)W習(xí)筆記之獲取位置信息操作。分享給大家供大家參考,具體如下:

前面介紹了微信小程序文件上傳、下載操作。這里分析一下獲取位置信息操作。

【獲取當(dāng)前位置信息】wx.getLocation()

getlocation.wxml:

<view> <button bindtap="getlocation">獲取位置</button></view>

getlocation.js:

Page({ getlocation: function () {  wx.getLocation({   type: 'wgs84', //wgs84返回gps坐標(biāo),gcj02返回國測局坐標(biāo)   success: function(res) {    console.log(res)   }  }) }})

點擊獲取位置按鈕,首次調(diào)用需要獲得用戶的scope.userLocation授權(quán):

點擊確定,獲得位置信息:

 

【​使用微信內(nèi)置地圖查看位置】 wx.openLocation()

openlocation.wxml:

<view> <button bindtap="openlocation">地圖位置</button></view>

openlocation.js:

Page({ openlocation: function () {  //首先調(diào)用wx.getLocation獲得當(dāng)前位置經(jīng)緯度  wx.getLocation({   type: 'gcj02', //wx.openLocation可用坐標(biāo)系   success(res) {    const latitude = res.latitude    const longitude = res.longitude    wx.openLocation({     latitude, //緯度     longitude, //經(jīng)度     scale: 18, //縮放比例:5~18     name: '北京', //位置名     address: '挺好', //地址詳細說明     success: function (res) {      console.log(res)     }    })   }  }) }})

點擊地圖位置按鈕,首次調(diào)用也需要獲得用戶的scope.userLocation授權(quán):

打開地圖獲得位置如下:

返回成功信息:


 

【打開地圖 選擇位置】 wx.chooseLocation()

chooselocation.wxml:

<view> <button bindtap="chooselocation">選擇位置</button></view>

chooselocation.js:

Page({ chooselocation: function () {  wx.chooseLocation({   success: function (res) {    console.log(res)   }  }) }})

點擊選擇位置按鈕,首次調(diào)用還需要獲得用戶的scope.userLocation授權(quán):

選擇位置頁面如下:

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 德钦县| 工布江达县| 灵台县| 竹山县| 刚察县| 博乐市| 滦平县| 宣威市| 泰州市| 泸定县| 靖边县| 河津市| 新泰市| 汝州市| 保亭| 张北县| 平潭县| 紫金县| 青浦区| 德江县| 天台县| 东至县| 西青区| 峨山| 长葛市| 永康市| 白城市| 安龙县| 灵武市| 当涂县| 黑水县| 清原| 辉南县| 阳曲县| 洞头县| 西乡县| 石家庄市| 吉首市| 永登县| 河曲县| 衡阳市|