• 输入地名查询出经纬度


    <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:#CBE1FF">
    <div style="730px;margin:auto;">
    要查询的地址:<input id="text_" type="text" value="宁波天一广场" style="margin-right:100px;"/>
    查询结果(经纬度):<input id="result_" type="text" />
    <input type="button" value="查询" onclick="searchByStationName();"/>
    <div id="container"
    style="position: absolute;
    margin-top:30px;
    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() {
    map.clearOverlays();//清空原来的标注
    var keyword = document.getElementById("text_").value;
    localSearch.setSearchCompleteCallback(function (searchResult) {
    var poi = searchResult.getPoi(0);
    document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
    map.centerAndZoom(poi.point, 13);
    var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 创建标注,为要查询的地方对应的经纬度
    map.addOverlay(marker);
    var content = document.getElementById("text_").value + "<br/><br/>经度:" + poi.point.lng + "<br/>纬度:" + poi.point.lat;
    var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
    marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
    // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    });
    localSearch.search(keyword);
    }
    </script>

    </html>

  • 相关阅读:
    ASP.NET MVC Framework 系列
    点站点链接出现短时间白屏或闪屏现象
    Asp.net Mvc Framework 一 (安装并建立示例程序)
    LINQ: Reconciling objects, relations and XML in the .NET framework
    乱学MonoRail A(问题随笔)
    可爱的MicrosoftAjax.js精简版(47K)
    成幻SNS(CHSNS#) 仿Facebook 风格发布,让您体验更专业的风格
    Asp.net Mvc Framework 二 (URL Routing初解)
    CHSNS# 1.05 正式发布 帮您创建您的Facebook
    Asp.net Mvc Framework 五 (向View传值以及Redirect)
  • 原文地址:https://www.cnblogs.com/pptt/p/7941224.html
Copyright © 2020-2023  润新知