收藏
回答

因为微信小程序sdk后,调用getLocation API 没有反馈?

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Document</title>

</head>

<body></body>

<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>

<script>

// 确保SDK加载完毕后再执行代码

window.onload = function () {

console.log(window.wx,'window');

if (wx.getLocation) {

console.log("wx API 加载成功");



if (window?.wx?.getLocation) {

window?.wx?.getLocation?.({

type: "gcj02", // 国内用gcj02坐标系

success(res) {

console.log("位置:", res.latitude, res.longitude); // 纬度、经度

},

fail(err) {

console.log("授权失败:", err); // 处理拒绝情况

},

});

}

} else {

console.error("window.wx 未加载,请检查 SDK 是否正确加载");

}

};

</script>

</html>



回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    1天前
    有用
登录 后发表内容