var currurl = decodeURIComponent(location.href.split('#')[0]);
$.ajax({//授权
url : "../initWXJSInterface",
dataType : 'json',
data : {
'url' : currurl//需要授权的页面
},
complete : function(XMLHttpRequest, textStatus) {},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("发生错误:" + errorThrown);
},
success : function(res) {
var appId = res.appId;
var nonceStr = res.nonceStr;
var jsapi_ticket = res.jsapi_ticket;
//alert(JSON.stringify(res));
var timestamp = res.timestamp;
var signature = res.signature;
wx.config({
debug: false,
appId: appId,
timestamp: timestamp,
nonceStr: nonceStr,
signature: signature,
jsApiList: [
'openLocation',
'getLocation',
]
});
}
});//ajaxEnd
//通过ready接口处理成功验证,加载直接调用的程序放在ready中,这里目前为空
wx.ready(function () {
});
//实现的是点击class是go的标签根据已知的经纬度打开内置地图
$(document).on('click', '.go', function(){
/* wx.getLocation({*///getLocation是获取到当前的地理位置(经纬度)
var status=$(".go")[0].id;//获取点击的索引
var i=parseInt(status);
var list=JSON.parse('${shopStrategyList}');
var storeLocation=list[i].storeLocation;
var latitude=parseFloat(storeLocation.split(",")[0]);//纬度
var longitude=parseFloat(storeLocation.split(",")[1]);//经度
wx.openLocation({
latitude: latitude,// 纬度,浮点数,范围为90 ~ -90
longitude: longitude,// 经度,浮点数,范围为180 ~ -180
name: list[i].storeName, //要写引号位置名
address: list[i].storeAddress, //要写引号地址详情说明
scale: 14,// 地图缩放级别,整形值,范围从1~28。默认为最大
infoUrl: "http://www.baidu.com" //要写引号// 在查看位置界面底部显示的超链接,可点击跳转
}); //end wx.openLocation
wx.error(function (res) {
alert(res.errMsg);
});
});
亲测有效
微信公众号开发之内置地图
最新推荐文章于 2023-07-14 15:18:29 发布