Wechat public account to obtain the positioning map (with latitude and longitude)

Configure parameters first: jsApiList: ["openLocation"]

Key point: parseFloat() must use this conversion, otherwise it will not work!

la =parseFloat(data.latitude)	//	重点parseFloat()
lo =parseFloat(data.longitude)

// 获取微信配置
function getconfig(){
	
	var urls = location.href;
	
	$.ajax({
		url: "http://saas.juwoxing.com/order/api.php?s=/api/share/getSignPackage",
		type: "get",
		dataType: "json",
		data:{
			url:urls,
		},
		success: function(res) {
			console.log(res);
	    var data = res;
			
			// 配置
			wx.config({
			  debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
			  appId: data.appId, // 必填,公众号的唯一标识
			  timestamp: data.timestamp, // 必填,生成签名的时间戳
			  nonceStr: data.nonceStr, // 必填,生成签名的随机串
			  signature: data.signature,// 必填,签名
			  jsApiList: ["openLocation"] // 必填,需要使用的JS接口列表
			});
			
			
		}
	})
	
}

reuse:

// 位置导航
function addr(){
	wx.openLocation({
		latitude: la, // 纬度,浮点数,范围为90 ~ -90
		longitude: lo, // 经度,浮点数,范围为180 ~ -180。
		name: '', // 位置名
		address: '', // 地址详情说明
		scale: 14, // 地图缩放级别,整形值,范围从1~28。默认为最大
		infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转
	});
}

 

Supongo que te gusta

Origin blog.csdn.net/weixin_44285250/article/details/107959703
Recomendado
Clasificación