调用wx.openLocation接口会在微信小程序内打开腾讯地图显示坐标位置
wx.openLocation的参数说明

index.wxml<view><button bindtap='getLocation'>获取当前位置</button><button bindtap='openmap'>在地图内查看当前位置</button></view>
index.jsPage({data:{latitude:"",longitude:""},getLocation: function(){let _that = this;wx.getLocation({type: 'gcj02',altitude:true,success(res) {const latitude = res.latitudeconst longitude = res.longitude_that.setData({latitude: latitude,longitude: longitude})}})},openmap: function(){let latitude = this.data.latitude;let longitude = this.data.longitude;console.log(latitude, longitude)wx.openLocation({latitude,longitude,scale: 14})}})
需要注意的是,wx.openLocation中使用的是GCJ-02国家测绘局坐标系,所以在使用wx.getLocation获取坐标的时候也要使用GCJ-02,这样才能保证定位的准确性。在地图中显示当前位置如图4.12所示。
