js调用高德地图的搜索api

            var city = $('#city')[0].value;
            AMap.plugin(['AMap.Autocomplete'],function(){
                var autoOptions = {
                    city: city,
                    input: community,
                };
                autocomplete= new AMap.Autocomplete(autoOptions);
                AMap.event.addListener(autocomplete, "select", function(e){
                    $('#community')[0].value = e.poi.name
                });
            });

记得加上

  <link rel="stylesheet" href="https://cache.amap.com/lbs/static/main.css"/>
    <script type="text/javascript"
            src="https://webapi.amap.com/maps?v=1.4.2&key=您申请的key值"></script>

    <script type="text/javascript" src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>

 

posted @ 2018-03-30 15:59  菲菲菲菲菲常新的新手  阅读(1860)  评论(0编辑  收藏  举报