<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>地址解析</title>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }
        body,
        button,
        input,
        select,
        textarea {
            font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
        }
        p {
            width: 1627px;
            padding-top: 3px;
            margin-top: 0px;
            overflow: hidden;
            line-height: 100%;
        }
        input#address {
            width: 300px;
        }
    </style>
    <script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
    </script>
</head>
<body onload="init()">
    <script type="text/javascript">
        $(function () {
            localStorage.wxdindex = 0;
        })
    </script>
    <script>
        var geocoder, map, marker = null;
        var init = function () {
            var center = new qq.maps.LatLng(39.916527, 116.397128);
            map = new qq.maps.Map(document.getElementById('container'), {
                center: center,
                zoom: 15,
            });
            //地址和经纬度之间进行转换服务
            geocoder = new qq.maps.Geocoder();
            //设置服务请求成功的回调函数
            geocoder.setComplete(function (result) {
                $("#wxd").append("<p>('" + orgid + "','" + result.detail.address + "'," + result.detail.location.lat
                    + "," + result.detail.location.lng + ")</p>");
                $
            });
            //若服务请求失败,则运行以下函数
            geocoder.setError(function () {
                $("#wxd2").append("<p>'" + source[Number(localStorage.wxdindex)].id + "'</p>");
            });
        }
        var orgid = "";
        var source = [{ id: "00003B1C483DE0000C80", address: "广东省广州市珠海区广州大厦南1276A区A12-A13,D区D1-D6,F区F9-F14" },
        { id: "00003BDB25DAF0000CA2", address: "山东省济宁高新区327国道南营村虎标工业园院内" }
       ];
        function codeAddress() {
            var i = localStorage.wxdindex;
            orgid = source[i].id;
            geocoder.getLocation(source[i].address);
            localStorage.wxdindex = Number(localStorage.wxdindex) + 1;
        }
        //定时任务总次数
        var maxCount = source.length;
        //随机单位时间范围
        var minNum = 1, maxNum = 10;
        //执行时间单位(1毫秒,10/10毫秒;100/百秒;1000/秒,)
        var p_unit = 100;
        //随机数函数
        function randomNum(minNum, maxNum) {
            switch (arguments.length) {
                case 1:
                    return parseInt(Math.random() * minNum + 1, 10);
                    break;
                case 2:
                    return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
                    break;
                default:
                    return 0;
                    break;
            }
        }
        //时间格式化
        function timestampToTime(timestamp) {
            var date = new Date();//时间戳为10位需*1000,时间戳为13位的话不需乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
            var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            strDate = Y + M + D + h + m + s;
            return strDate;
        }
        //随机数实例函数
        function num(unit) {
            if (!unit)
                unit = p_unit;
            var n = randomNum(1, 5);
            var nowDate = new Date().getTime();
            console.log(timestampToTime(nowDate) + "间隔" + n * unit / 1000 + "秒执行");
            return n * unit;
        }
        //执行任务.
        var ii = setInterval(befor, num());
        var index = 1;
        function befor() {
            //方法可取消由 setInterval() 函数设定的定时执行操作
            clearInterval(ii);
            //主函数
            codeAddress();
            console.log("淘小人提醒您:任务总次数>>>"+maxCount+",  当前执行次数>>>" + index)
            //递归
            if (index <= 55) {
                ii = setInterval(befor, num())
            } else {
                console.log("淘小人提醒您,任务完毕.总执行次数>>>" + index)
            }
            //递归使用,当前索引+1
            index = index + 1;
        }
    </script>
    <div>
        <input id="address" type="textbox" value="中国,北京,海淀区,海淀大街38号">
        <button onclick="codeAddress()">search</button>
    </div>
    <div style="width:603px;height:300px" id="container"></div>
    <p>输入地址,点击search进行地址解释,点击Marker会弹出反查结果。</p>
    <div id="wxd"></div>
    <div id="wxd2" style="color:red"></div>
</body>
</html>