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


wx.getLocation(object)


<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




wx.chooseLocation(object)


<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>
新聞熱點(diǎn)
疑難解答
圖片精選