百度地图 城市切换

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/TextIconOverlay/1.2/src/TextIconOverlay_min.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/MarkerClusterer/1.2/src/MarkerClusterer_min.js"></script>
    <title>23.1 城市切换</title>
</head>
<body>
    <div class="wrapper">      
    <p>我要去<input id="txtSearch" type="text" value="上海"/><input type="button" value="GO" onclick="search()"/></p>  
        <div class="container clearfix">
            <div class="clearfix">
                <div style="clear: both;">
                    <div style="float: left; width: 500px; height: 340px; border: 1px solid gray" id="container">
                    </div>                    
                </div>
            </div>
    </div>
</body>
</html>
<script type="text/javascript">
    var map = new BMap.Map("container");
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 16);

    var city = new BMap.LocalSearch(map, {
        renderOptions: {
            map: map,
            autoViewport:true
        }
    });

    function search() {
        var s = document.getElementById("txtSearch").value;
        city.search(s);
    }
</script>

posted on 2014-12-03 18:45  AlexGeng  阅读(1851)  评论(0编辑  收藏  举报

导航