tp5-微信地理位置
对于一个不咋懂微信开发的偶,前两天总监给个需求过来,没错啦,就是微信地理位置。
不得不说,一开始很谎,以为很难,其实很简单的。
很多人都找不到微信公众号测试号登陆页面,我就提供一下了啊各位大锅们
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
HTML代码
<!DOCTYPE html>
<html>
<head>
<title>微信获取地理位置</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- 这行代码不能少,用微信的接口都会用到这引入 -->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
// 配置
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '{$wx.appId}', // 必填,公众号的唯一标识
timestamp: '{$wx.timestamp}', // 必填,生成签名的时间戳
nonceStr: '{$wx.nonceStr}', // 必填,生成签名的随机串
signature: '{$wx.signature}',// 必填,签名
jsApiList: ['openLocation'] // 必填,需要使用的JS接口列表
});
</script>
</head>
<body>
<img src="./1.png" onclick="addrss(x,y,name,address)">
</body>
<script type="text/javascript">
// 需要获取的时候 执行方法即可
// 注意经纬度必须是 浮点数类型
function addrss(x,y,name,address) {
wx.openLocation({
latitude: y, // 纬度,浮点数,范围为90 ~ -90
longitude: x, // 经度,浮点数,范围为180 ~ -180。
name: name, // 位置名
address: address, // 地址详情说明
scale: 15, // 地图缩放级别,整形值,范围从1~28。默认为最大
infoUrl: '' // 在查看位置界面底部显示的超链接,可点击跳转
});
}
</script>
</html>