2013-06-20 81 views
4

我正在嘗試在我的ASP.net Web窗體頁面中顯示Google Map。在ASP.net中顯示Google Map API V3 Web窗體

的JavaScript是如下:

<script type="text/javascript" 
    src="https://maps.googleapis.com/maps/api/js?key=xxxxx&sensor=false"> 
</script> 
<script type="text/javascript"> 
    var map; 
    function initialize() { 

     var mapOptions = { 
      zoom: 8, 
      center: new google.maps.LatLng(-34.397, 150.644), 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     var mapcv = document.getElementById('map-canvas');    

     map = new google.maps.Map(mapcv, 
      mapOptions); 

    } 

    google.maps.event.addDomListener(window, 'load', initialize); 

</script> 

我用下面的HTML,如果我把表單標籤內div標籤這是行不通的。

<form id="form1" runat="server"> 
    <div id="map-canvas" ></div> 
</form> 

但是,如果我移動Div標籤形式標籤之外如下,它的工作原理

<div id="map-canvas" ></div> 
<form id="form1" runat="server">   
    </form> 

我想把div標籤的形式中。你能幫我怎麼做到嗎?謝謝。

回答

4

只需設置div寬度和高度即可看到它!你的地圖是有,但不可見:)

<div id="map_canvas" style="width:600px;height:400px"></div> 

你也可以將它們設置在CSS中的標題:

<style> 
    html, body, #form1, #map_canvas 
    { 
     margin: 0; 
     padding: 0; 
     height: 100%; 
    } 
</style>