继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

基于高德接口封装地址搜索服务

幸福拾荒者
关注TA
已关注
手记 6
粉丝 8
获赞 190
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>高德地图查询</title>
</head>

<body>
    <div class="search">
        <input type="text" id='intext' name="">
        <button id="butseach">搜索</button>
    </div>
    <div id="GdList">
    </div>
</body>

</html>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=‘开发者秘钥’&plugin=AMap.PlaceSearch"></script>
<script type="text/javascript">
window.onload = function() {

        var intext = document.getElementById('intext');
        var butseach = document.getElementById('butseach');
        var GdList = document.getElementById('GdList');

        eflower_GdMap.GdSearchload();

        butseach.onclick = function() {

            var val = intext.value;

            eflower_GdMap.GdSearch(val, GdList);
        }
    }

//初始化业务加载 搜索插件,自定义div map;
//eflower_GdMap.GdSearchload();
//第一个传值是搜索的内容 第二个查询出来的数据的接收容器
//eflower_GdMap.GdSearch(val,GdList);

eflower_GdMap = {
    GdSearchload: function() {
        var e = document.body,
            a = document.createElement("div");
        a.style.display = "none";
        a.setAttribute("id", "MarkMap");
        e.appendChild(a);
        a = document.createElement("script");
        a.setAttribute("type", "text/javascript");
        a.setAttribute("src", "http://cache.amap.com/lbs/static/PlaceSearchRender.js");
        e.appendChild(a)
    },
    GdSearch: function(e, a) {
        new AMap.Map("MarkMap");
        (new AMap.PlaceSearch({
            pageSize: 100,
            pageIndex: 1
        })).search(e, function(e, g) {
            if ("complete" === e && "OK" === g.info) {
                var d = g.poiList.pois,
                    f = document.createElement("ul");
                f.style.listStyle = "none";
                f.style.margin = "10px";
                f.style.padding = "0px";
                for (var b = 0; b < d.length; b++)
                    if ("\u5730\u540d\u5730\u5740\u4fe1\u606f;\u666e\u901a\u5730\u540d;\u5730\u5e02\u7ea7\u5730\u540d" != d[b].type && "\u5730\u540d\u5730\u5740\u4fe1\u606f;\u666e\u901a\u5730\u540d;\u7701\u7ea7\u5730\u540d" != d[b].type && "\u5730\u540d\u5730\u5740\u4fe1\u606f;\u666e\u901a\u5730\u540d;\u533a\u53bf\u7ea7\u5730\u540d" != d[b].type) {
                        var c = document.createElement("li");
                        c.style.height = "35px";
                        c.style.width = "100%";
                        c.style.paddingLeft = "10px";
                        c.style.lineHeight = "35px";
                        c.style.borderBottom = "1px solid #e5e5e5";
                        c.setAttribute("lg", d[b].location.lng + "," + d[b].location.lat);
                        c.innerHTML = d[b].name;
                        f.appendChild(c)
                    }
                a.appendChild(f)
            } else alert("\u67e5\u65e0\u6570\u636e\uff01\uff01")
        });
        new Lib.AMap.PlaceSearchRender
    }
};
</script>
打开App,阅读手记
8人推荐
发表评论
随时随地看视频慕课网APP

热门评论

兄弟,问下!我查出的数据,想圆圈覆盖物展示,怎么设置!我只看到中心点设置的

查看全部评论