2012-04-01 79 views
1

我試圖將iframe中的Google地圖居中。下面的代碼是iframe的內容。 標記不在框架的中心。Google地圖中的中心標記

缺什麼?

<!DOCTYPE html> 
<html> 
    <head> 
    <style type="text/css"> 
     html { height: 100% } 
     body { height: 100%; margin: 0; padding: 0 } 
     #map_canvas { height: 100% } 
    </style> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=MYAPIKEY&sensor=false"></script> 
    <script type="text/javascript"> 


function initialize() { 
     var myLatlng = new google.maps.LatLng('<?php echo $this->uri->segment(5); ?>', '<?php echo $this->uri->segment(4); ?>'); 
      var myOptions = { 
      zoom: 8, 
       mapTypeControl: false, 
       scaleControl: false, 
      center: myLatlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
      } 
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

      var marker = new google.maps.Marker({ 
       position: myLatlng, 
       map: map, 
       title:"Hello World!" 
      }); 

     } 


     initialize(); 


    </script> 
    </head> 
    <body onload="initialize()"> 
    <div id="map_canvas" style="width:100%; height:100%"></div> 
    </body> 
</html> 

UPDATE

我想我已經解決了它買設定一個固定大小的map_canvas提供,而不是使用100%。 我現在工作好多了。

+0

是的,但問題是當我把它放在一個iframe中時,它不再居中。 – 2012-04-01 11:04:32

+0

@工程師。請創建一個答案,我會選擇它作爲最佳答案。 – 2012-04-02 10:27:41

回答