Foxtable(狐表)用户栏目专家坐堂 → 微信中获取用户的地理位置


  共有5555人关注过本帖树形打印复制链接

主题:微信中获取用户的地理位置

帅哥哟,离线,有人找我吗?
lihe60
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6848 积分:43334 威望:0 精华:0 注册:2009/3/2 14:07:00
  发帖心情 Post By:2017/6/1 15:12:00 [显示全部帖子]

源文件可以上传一下吗?

 回到顶部
帅哥哟,离线,有人找我吗?
lihe60
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:6848 积分:43334 威望:0 精华:0 注册:2009/3/2 14:07:00
  发帖心情 Post By:2017/6/1 15:13:00 [显示全部帖子]

以下是引用ap9709130在2017/5/11 9:36:00的发言:
我就是把例子改了下,很简单的,代码如下:
Dim wb As New weui
        wb.AppendHTML("<script src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>",True) '引入JS-SDK库
        wb.AppendHTML("<script src='./hito/jssdk.js'></script>") '引入脚本文件
        '在页面注入权限验证配置
        Dim st As New Date(1970,1,1,8,0,0)
        Dim appid As String = "wxa05c11a75642d325" 'CorpID
        Dim timestamp As Integer = CInt((Date.Now - st).TotalSeconds()) '时间戳
        Dim noncestr As String = Rand.NextString(16) '随机字符
        Dim url As String  = e.Request.URL.ToString '当前页面地址
        Dim signature As String = Functions.Execute("GetJsSignature", noncestr, timestamp, url) '生成权限验证签名
        Dim cfg As String = "wx.config({appId:'{0}',timestamp:{1},nonceStr:'{2}',signature:'{3}',jsApiList:['getLocation']});"
        wb.AppendHTML("<script>" & CExp(cfg,appid,timestamp,noncestr,signature) & "</script>",True)
        '开始正常生成网页内容
        wb.AddForm("","form1","test.htm")
        With wb.AddInputGroup("form1","ipg1","产品输入")
            .AddInput("product","产品","text")
            With .AddInputCell("ic1")
                .AddLabel("lbh","编号",0)
                .AddInput("number","text",1)
                .AddVcodeButton("scan","扫码输入",2) '增加二维码扫描按钮,2表示显示在右边
            End With
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1", "确定", "submit")
        End With
        e.WriteString(wb.Build) '生成网页

JS 代码如下 :

wx.ready(function () {
    document.getElementById('scan').onclick = function () {
        wx.getLocation({
            type: 'wgs84',
            success: function (res) {
                document.getElementById('number').value = res.latitude;
document.getElementById('product').value = res.longitude;
            }
        });
    };
});
wx.error(function (res) {
    //alert(res.errMsg);
});

这样就可以获得地理位置了。我还把这个地理位置在百度地图里看了,定位还是挺准的。


源文件可以上传一下吗?


 回到顶部