index2.php 2.04 KB
<?php
use yii\helpers\Html;
$site = $this->params['site'];
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>map test </title>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp"></script>
</head>
<body>
<div id="content-map">
</div>
<script>
    window.$site = {
        base_url : '<?=$site->base_url?>',
        assets_url : '<?=$site->assets_url?>',
        title: '<?=$site->title?>',
        desc: '<?=$site->desc?>',
        url: '<?=$site->url?>',
        icon: '<?=$site->icon?>',
        appid: '<?=$site->appid?>',
        timestamp: '<?=$site->timestamp?>',
        noncestr: '<?=$site->noncestr?>',//noncestr
        signature: '<?=$site->signature?>',//signature
        user_bridge_url: '<?=$site->user_bridge_url?>',
        sn: '<?=$site->sn?>'
    }
    var map =null;
    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: params.appid, // 必填,公众号的唯一标识
        timestamp: params.timestamp, // 必填,生成签名的时间戳
        nonceStr: params.noncestr, // 必填,生成签名的随机串
        signature: params.signature,// 必填,签名,见附录1
        jsApiList: ['openLocation','getLocation','scanQRCode'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
    });
    wx.ready(function () {
        var center = new qq.maps.LatLng(39.916527,116.397128);
         map = new qq.maps.Map(document.getElementById('content-map'));

        wx.getLocation({
            type:'gcj02',/*默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'*/
            success: function (res) {
                var lntLng = new qq.maps.LatLng(res.latitude,res.longitude);
                map.setCenter(lntLng);
            }
        })
    })


</script>
</body>
</html>