【问题标题】:Google map is not displaying without form element in asp.net webform谷歌地图没有在asp.net webform中显示没有表单元素
【发布时间】:2015-07-03 23:37:19
【问题描述】:

我的aspx页面内容是这样的

<body>
 <div id="mapDiv"></div>
 <form id="form" runat="server"></form>
</body>

并在代码隐藏中创建脚本

string script = string.Format(@"function initialize() {{
                    var mapOptions = {{
                    center: new google.maps.LatLng({0},{1}),
                    zoom: 8,
                    tilt: 30
                    }};

                var map = new google.maps.Map(document.getElementById('mapDiv'), mapOptions);

                {2}                                                        
                }}

                function addInfoWindow(marker, content) {{
                    var infoWindow = new google.maps.InfoWindow({{
                        content: content
                    }});

                    google.maps.event.addListener(marker, 'click', function () {{
                        if (currentInfoWindow != null) {{
                            currentInfoWindow.close(); 
                        }}

                        infoWindow.open(marker.get('map'), marker);
                        currentInfoWindow = infoWindow;
                    }});
                }}                                                          

                google.maps.event.addDomListener(window,'load',initialize);
                var currentInfoWindow = null;",
                coordinates[0], coordinates[1], DrawMarkers(groups));

ClientScript.RegisterStartupScript(this.GetType(), "mapInit", script, true);

如果 aspx 包含 div 和表单元素,就像现在一样,一切正常。但是我必须使用这个 aspx 文件的母版页。当我相应地更改其内容时,我必须删除表单元素,因为主文件中已经有一个。但是当我删除表单元素时,地图就消失了。

【问题讨论】:

    标签: asp.net forms google-maps google-maps-api-3


    【解决方案1】:

    出于某种原因,在我的自定义 CSS 中,我设置了“高度:100%”并且浏览器不喜欢它,尽管“宽度:100%”很好。所以我通过使用

    解决了我的问题
    var mapDiv = document.getElementById('mapDiv'); 
    var height = Math.max(0, document.documentElement.clientHeight - 110).toString();
    mapDiv.setAttribute('style','height: ' + height + 'px'); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-26
      • 2014-12-27
      • 1970-01-01
      • 1970-01-01
      • 2017-11-20
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      相关资源
      最近更新 更多