<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
        .hn {
            margin: 10px 0 5px 0
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=DhzdodNVxoDSiBzRfZod4FG8"></script>
    <title>地图</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    //map.html?a=南通市城山家园&hn=城山家园</br>同普路1220号&c=南通市&p=120.890824,31.971025
    // 创建Map实例
    var map = new BMap.Map("allmap");
    var url_address = '{{address}}';
    var url_city = '{{city}}';
    var url_point = '{{point}}';
    var url_houseName = "<a class='hn'>{{houseName}}</a>";
    if (url_point) {
        var pointLng = url_point.split(',')[0];
        var pointLat = url_point.split(',')[1];
        fromPoint(pointLng,pointLat);
    } else if (!!url_address) {
        fromAddress();
    }

    function fromAddress() {
        // 创建地址解析器实例
        var myGeo = new BMap.Geocoder();
        // 将地址解析结果显示在地图上,并调整地图视野
        myGeo.getPoint(url_address, function (point) {
            if (point) {
                map.centerAndZoom(point, 18);
                map.addOverlay(new BMap.Marker(point));
                showinfo(point);
            } else {
                alert("您选择地址没有解析到结果!");
            }
        },url_city);
    }
    function fromPoint(lng,lat) {
        var point = new BMap.Point(lng, lat);
        map.centerAndZoom(point, 18);
        map.addOverlay(new BMap.Marker(point));
        showinfo(point);
    }
    function showinfo(point) {
        var opts = {
            width: 0,     // 信息窗口宽度
            height: 0,     // 信息窗口高度
            //title: "楼盘名称",  // 信息窗口标题
            enableCloseOnClick: false, //
            offset: new BMap.Size(10, -20) //信息窗位置偏移值
        }
        var infoWindow = new BMap.InfoWindow(url_houseName, opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow, point); //开启信息窗口
    }
    function getUrlParam(name) {
        var reg= new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURI(r[2]);
        return null;
    }
</script>
