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

首頁 > 課堂 > 小程序 > 正文

微信小程序3種位置API的使用方法詳解

2020-03-21 15:26:21
字體:
供稿:網(wǎng)友

獲取位置

獲取當(dāng)前的地理位置、速度。當(dāng)用戶離開小程序后,此接口無法調(diào)用;當(dāng)用戶點(diǎn)擊“顯示在聊天頂部”時(shí),此接口可繼續(xù)調(diào)用。

微信小程序,位置API

微信小程序,位置API

wx.getLocation(object)

微信小程序,位置API

微信小程序,位置API

<view class="container"> <button bindtap='getLocation'>獲取位置</button> <view wx:if="{{latitude !=''}}">  <view>緯度:{{latitude}}</view>  <view>經(jīng)度:{{longitude}}</view>  <view>速度:{{speed}}</view>  <view>位置的精確度:{{accuracy}}</view>  <view>高度:{{altitude}}</view>  <view>垂直精度:{{accuracy}}</view>  <view>水平精度:{{accuracy}}</view> </view></view>
//index.js//獲取應(yīng)用實(shí)例const app = getApp()Page({ data: {  latitude: '',  longitude: '',  speed: '',  accuracy: '',  altitude:'',  verticalAccuracy: '',  horizontalAccuracy:'' }, onLoad: function () { }, getLocation:function(){  var _this=this;  wx.getLocation({   type: 'wgs84',   success: function (res) {    var latitude = res.latitude    var longitude = res.longitude    var speed = res.speed    var accuracy = res.accuracy    var altitude = res.altitude    var verticalAccuracy = res.verticalAccuracy    var horizontalAccuracy = res.horizontalAccuracy    _this.setData({     latitude: latitude,     longitude: longitude,     speed: speed,     accuracy: accuracy,     altitude: altitude,     verticalAccuracy: verticalAccuracy,     horizontalAccuracy: horizontalAccuracy    })   }  }) }})

打開地圖選擇位置

wx.chooseLocation(OBJECT)

打開地圖選擇位置。 

需要用戶授權(quán) scope.userLocation

微信小程序,位置API

微信小程序,位置API

微信小程序,位置API

微信小程序,位置API

wx.chooseLocation(object)

微信小程序,位置API

微信小程序,位置API

<view class="container"> <button bindtap='getLocation'>打開地圖選擇位置</button> <view wx:if="{{address !=''}}">  <view>位置名稱:{{name}}</view>  <view>詳細(xì)地址:{{address}}</view>  <view>緯度:{{latitude}}</view>  <view>經(jīng)度:{{longitude}}</view> </view></view>
//index.js//獲取應(yīng)用實(shí)例const app = getApp()Page({ data: {  name: '',  address: '',  latitude: '',  longitude: '' }, onLoad: function () { }, getLocation:function(){  var _this=this;  wx.chooseLocation({   success: function (res) {    var name = res.name    var address = res.address    var latitude = res.latitude    var longitude = res.longitude    _this.setData({     name: name,     address: address,     latitude: latitude,     longitude: longitude    })   }  }) }})

?使用微信內(nèi)置地圖查看位置

使用微信內(nèi)置地圖查看位置。

微信小程序,位置API

微信小程序,位置API

wx.openLocation(OBJECT)

微信小程序,位置API

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 称多县| 屯昌县| 墨竹工卡县| 安福县| 花垣县| 乐山市| 河西区| 勐海县| 南漳县| 汝城县| 平江县| 安阳县| 德钦县| 清河县| 曲沃县| 宕昌县| 临沂市| 柏乡县| 黄冈市| 三原县| 闵行区| 纳雍县| 西平县| 慈利县| 福泉市| 红桥区| 延庆县| 聂拉木县| 沂南县| 长葛市| 招远市| 温州市| 方城县| 土默特右旗| 台前县| 福贡县| 淳化县| 米脂县| 丹巴县| 镇平县| 汤原县|