zoukankan      html  css  js  c++  java
  • 微信公众号开发获取当前位置

    微信开始时,获取用户当前地理位置可以不用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>

  • 相关阅读:
    NOIP初赛知识点大全-普及+提高组
    cron表达式详解,cron表达式写法,cron表达式例子
    n2n的编译和运行、配置
    Visual Studio 2017 扩展
    iis url重写
    http重定向到https
    基于git命令的代码统计方法
    UseSwagger
    docker中mysql数据库的数据导入和导出
    Win10远程桌面提示你的凭据不工作的处理方法
  • 原文地址:https://www.cnblogs.com/Ushadow/p/7246196.html
Copyright © 2011-2022 走看看