引入 jsSdk文件:
<script src="${ctx}/static/js/foreman/jweixin-1.2.0.js"></script>
$.ajax({
type: 'get',
url: '请求地址', // 获取下面字符的请求地址
dataType: 'json',
success: function (ret) {
if (ret.code == 0) {
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: ret.appId, // 必填,公众号的唯一标识
timestamp: ret.timestamp, // 必填,生成签名的时间戳
nonceStr: ret.nonceStr, // 必填,生成签名的随机串
signature: ret.signature,// 必填,签名,见附录1
jsApiList: ['checkJsApi',
'getNetworkType',//网络状态接口
'openLocation',//使用微信内置地图查看地理位置接口
'getLocation' //获取地理位置接口
] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
} else {
this.layerOpen("数据请求失败");
}
}
});
"查看位置"
openLocations: function (addressUrl, longitude, latitude)
// 传入经纬度和具体地址
if (longitude == null || latitude == null) {
alert("地址转换失败");
} else {
wx.openLocation({
type: "gcj02",
latitude: latitude, //必填 维度
longitude: longitude, //必填 经度
name: addressUrl,
address: addressUrl,
scale: 20,
});
}
},