• 微信公众号开发获取当前位置


    微信开始时,获取用户当前地理位置可以不用html5(因为每次都会弹出获取位置的窗口),就可以使用微信的接口获取经纬度,再通过百度地图转变成某城市的名字

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?type=quick&ak=百度地图密钥&v=1.0"></script>

    <script type="text/javascript" >
    wx.config({

    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。

    appId: '${appId}', // 必填,公众号的唯一标识
    timestamp: '${ timestamp}' , // 必填,生成签名的时间戳
    nonceStr: '${ nonceStr}', // 必填,生成签名的随机串
    signature: '${ signature}',// 必填,签名,见附录1
    jsApiList: [

    'getLocation' //获取地理位置接口

    ]
    });

    wx.ready(function(){
    wx.getLocation({
    type: 'wgs84',
    complete:function(argv){
    if(argv.errMsg=="getLocation:fail"){
    alert(JSON.stringify(res));
    var gc = new BMap.Geocoder();
    var pointAdd = new BMap.Point(res.longitude, res.latitude);
    gc.getLocation(pointAdd, function(rs){
    var city = rs.addressComponents.city;
    alert(city);
    }
    );
    }else{
    alert("ok");
    }
    },
    cancel: function (res) {
    alert('用户拒绝授权获取地理位置');
    }
    });
    });
    wx.error(function (res) {
    alert("调用微信jsapi返回的状态:"+res.errMsg);
    });
    });

    </script>

  • 相关阅读:
    Node.js 笔记03
    Node.js 笔记02
    Node.js 笔记01
    源代码管理工具-git
    ES6笔记01
    07_查找、软链接、打包压缩、软件安装
    06_系统信息相关命令
    oracle序列中cache和nocache
    PL/SQL规范、块、过程、函数、包、触发器
    对Xcode菜单选项的详细探索(干货)
  • 原文地址:https://www.cnblogs.com/Ushadow/p/7246196.html
Copyright © 2020-2023  润新知