使用步骤请参考微信开放文档JS-SDK说明文档中的JSSDK使用步骤
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="../../js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<title>Title</title>
</head>
<body>
<div>
</div>
</body>
</html>
<script>
getWxJSSDK()
//获取微信sdkConfig
function getWxJSSDK(){
// 拿到当前页面url
var thisPageUrl = location.href;
$.ajax({
url: "url",
type: "post",
dataType: "json",
data: {
"url": thisPageUrl,
},
success: function (result) {
console.log(result);
wx.config({
debug: false, // true开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: result.appId,
timestamp: result.timestamp,
nonceStr: result.nonceStr,
signature: result.signature,
jsApiList: ['openLocation', 'getLocation' ]
});
},
error: function (err) {
console.log("fail");
}
});
}
wx.ready(function () {
wx.getLocation({
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
$("#latitude").val(latitude);
$("#longitude").val(longitude);
console.log(JSON.stringify(res))
}
});
});
</script>
通过JSSDK可以获得经纬度坐标,然后我用的是腾讯地图逆地址解析