<!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>
