<button bindtap='getLocation'>打开地图选择位置</button>
js
getLocation: function () {
wx.getLocation({//
type:'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function (res) {
console.log(res.latitude); console.log(res.longitude);
wx.openLocation({
latitude: 31, // 纬度,范围为-90~90,负数表示南纬
longitude: 121, // 经度,范围为-180~180,负数表示西经
scale: 8, // 缩放比例
name:"测试",
address:"测试详细地址",
success:function(r){
console.log(r)
}
})
}
})
},
app.json
"pages":[
"pages/index/index"
],
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},