1、获取位置
wx.getLocation(OBJECT)
获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用;当用户点击“显示在聊天顶部”时,此接口可继续调用。
var that=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
that.setData({
longitude: longitude,
latitude: latitude,
speed: speed,
accuracy: accuracy,
altitude: altitude,
verticalAccuracy: verticalAccuracy,
horizontalAccuracy: horizontalAccuracy
})
}
})
wx.chooseLocation(OBJECT)
打开地图选择位置
2、查看位置
wx.openLocation(OBJECT)
使用微信内置地图查看位置
wx.getLocation({
type:

本文介绍了微信小程序中关于位置的操作,包括通过wx.getLocation获取当前位置,wx.chooseLocation打开地图选择位置,以及使用wx.openLocation查看位置。此外,还详细讲解了如何利用wx.createMapContext进行地图组件的控制,实现如getCenterLocation、translateMarker和includePoints等方法的功能。
2万+

被折叠的 条评论
为什么被折叠?



