开发者

Google Maps will not show with nested Div's?

Essentially the code wont show when I provide some sort of page container or any divs around the maps.

Header

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="<?php echo base_url(); ?>body_css.css" type="text/css" />

<!--///////////////////////////////////////////////////////////////////////////////////////// -->

    <?php
        $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].
                $_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].":8888".$_SERVER['REQUEST_URI'];
    ?>

<!--///////////////////////////////////////////////////////////////////////////////////////// -->
    <?php if($url == base_url()): {?>
        <title>Welcome to CodeIgniter</title>
    <?php } endif; ?>

<!--///////////////////////////////////////////////////////////////////////////////////////// -->

    <?php if($url == base_url()."index.php/Welcome/maps"): {?>
        <title>Welcome to this site</title>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

        <script type="text/javascript"
            src="http://maps.google.com/maps/api/js?sensor=false">
        </script>
        <style type="text/css">
          html { height: 100% }
          body { height: 100%; margin: 0px; padding: 0px }
          #map_canvas { height: 100% }
        </style>
        <script type="text/javascript">

          function initialize() {
            var latlng = new google.maps.LatLng(30.436506, -84.302591);
            var myOptions = {
              zoom: 16,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map = new google.maps.Map(document.getElementById("map_canvas"),
                myOptions);

         //////////////////////////////////////////////////////

 开发者_JAVA百科           var latlng2 = new google.maps.LatLng(30.444523, -84.298766);
            var myOptions2 = {
              zoom: 16,
              center: latlng2,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map2 = new google.maps.Map(document.getElementById("map_canvas2"),
                myOptions2);


           //////////////////////////////////////////////////////

            var latlng3 = new google.maps.LatLng(30.442334, -84.303793);
            var myOptions3 = {
              zoom: 16,
              center: latlng3,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map3 = new google.maps.Map(document.getElementById("map_canvas3"),
                myOptions3);


           //////////////////////////////////////////////////////

            var latlng4 = new google.maps.LatLng(30.440354, -84.301604);
            var myOptions4 = {
              zoom: 16,
              center: latlng4,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };

            var map4 = new google.maps.Map(document.getElementById("map_canvas4"),
                myOptions4);
          }

        </script>
    <?php } endif; ?>

</head>
<body>
    <div id="heading">
        <h1>Ultimate Campus Services</h1>
            <p>
                <a href="<?php echo base_url(); ?>">About Us</a> |
                <a href="<?php echo base_url(); ?>index.php/Welcome/maps">Maps</a>
            </p>
            <hr>
    </div>

Main Page

 <!--<div id="table_for_maps" >-->

<p>Stadium Student Parking</p>
<p># Spots Available</p>
<div id="map_canvas" style="width:20%; height:20%" ></div>
<p><a href="<?php base_url() . "index.php/Welcome/maps_zoomed" ?>">Zoom</a></p>

<p>------------------------------<br/></p>

<p>Woodward Faculty Lot</p>
<p># Spots Available</p>
<div id="map_canvas2" style="width:20%; height:20%"></div>
<a href="<?php base_url() . "index.php/Welcome/maps_zoomed" ?>">Zoom</a>

<p>------------------------------<br/></p>

<p>GYM LOT</p>
<p># Spots Available</p>
<div id="map_canvas3" style="width:20%; height:20%"></div>
<a href="<?php base_url()."index.php/Welcome/maps_zoomed" ?>">Zoom</a>

<p>------------------------------<br/></p>

<p>GYM LOT</p>
<p># Spots Available</p>
<div id="map_canvas4" style="width:20%; height:20%"></div>
<a href="<?php base_url()."index.php/Welcome/maps_zoomed" ?>">Zoom</a>
<!--</div>-->

Footer

    </body>
</html>


I'd hazard a guess that all the map canvas divs have the right width, but 0 height. You need to set a height on a wrapper of the map divs (such as the commented out <div id="table_for_maps" >) or set a non-percent height on the map divs (such as 300px).

You should use a tool like Firebug (Safari and Chrome come with built-in equivalents) to inspect the CSS yourself, to get more information about the problem.


Fixed my issue with API v3. Initial value supplied by Google was:

<div id="map_canvas" style="width:100%; height:100%"></div> 

Just change the values to a pixel size such as:

<div id="map_canvas" style="width:850px,;height:600px"></div> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜