当前位置 : 主页 > 网页制作 > html >

百度地图根据关键字搜索显示区域

来源:互联网 收集:自由互联 发布时间:2021-06-12
html xmlns ="http://www.w3.org/1999/xhtml" head title 根据地址查询经纬度 / title meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" script type ="text/javascript" src ="http://api.map.baidu.com/api?v=1.3" / script
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>根据地址查询经纬度</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
  </head>
<body style="background:#f9f9f9; margin:0 auto">
    <div style="width:730px;margin:30px auto;">   
        要查询的地址:<input id="address" type="text" value="北京天安门" style="margin-right:50px;"/>
        查询结果(经纬度):<input id="coordinate" type="text" />
        <input type="button" value="查询" onclick="searchByStationName();"/>

        <div id="container" style="position:absolute; margin-top:30px; width:730px; height:590px; top:50; border:1px solid gray; overflow:hidden;"></div>
    </div>
</body>
<script type="text/javascript">
    var map = new BMap.Map("container");
    map.centerAndZoom("北京市", 12);
    map.enableScrollWheelZoom();    //启用滚轮放大缩小,默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽,默认禁用

    map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
    map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
    map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角,打开

    var localSearch = new BMap.LocalSearch(map);
    localSearch.enableAutoViewport(); //允许自动调节窗体大小


function searchByStationName() { 

    var keyword = document.getElementById("address").value;

    localSearch.setSearchCompleteCallback(function (searchResult) {
        var poi = searchResult.getPoi(0); 

         // 创建Map实例 
        var mPoint = new BMap.Point(poi.point.lng, poi.point.lat);  

        map.enableScrollWheelZoom();
        map.centerAndZoom(mPoint,15);

        var circle = new BMap.Circle(mPoint,1000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
        map.addOverlay(circle);
        var local =  new BMap.LocalSearch(map, {renderOptions: {map: map, autoViewport: false}});  
        local.searchNearby(景点,mPoint,1000);

    });

    localSearch.search(keyword);
} 
</script>
</html>
网友评论