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

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 11:55:20
字體:
供稿:網(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: '挺好', //地址詳細(xì)說明     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):

選擇位置頁面如下:

選擇一個位置,點擊右上角確定,返回信息如下:

 (經(jīng)、緯度使用 gcj02 國測局坐標(biāo)系)

希望本文所述對大家微信小程序開發(fā)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沅江市| 孝义市| 华容县| 弋阳县| 台东县| 平潭县| 财经| 台安县| 休宁县| 武宁县| 芷江| 双辽市| 延安市| 新和县| 中阳县| 江达县| 双柏县| 浦江县| 万荣县| 阳高县| 广饶县| 咸阳市| 瑞金市| 平安县| 大英县| 莒南县| 图们市| 延边| 武川县| 鹤壁市| 天镇县| 赤壁市| 邻水| 浏阳市| 鱼台县| 屏山县| 平南县| 宜州市| 鄂伦春自治旗| 信丰县| 长海县|