0

I am trying to integrate google maps with my sample website application using Bootstrap 4 and google maps are not showing. I inspect the element and see the property overflow:hidden and when I remove the property, it shows the map outside the browser canvas little bit, but I am unable to figure out the issue and fix it.

<!doctype html>
<html lang="en">
    <head>
        <!-- Required meta tags -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">


        <link href="main.css" rel="stylesheet">  
        <link href="css/all.css" rel="stylesheet"> <!--load all styles -->

        <!-- Bootstrap CSS -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
        <link href="https://fonts.googleapis.com/css?family=Vibur&display=swap" rel="stylesheet">

        <title>Chicken King</title>
    </head>
    <body>

        <div class="container-fluid">

            <div class="row text-center">
                <div class="col-md-12 text-center">
                    <h1 id="logo">Chicken King</h1>
                </div>
            </div>
            <div class="row">

                <div id="demo" class="carousel slide" data-ride="carousel">
                    <ul class="carousel-indicators">
                        <li data-target="#demo" data-slide-to="0" class="active"></li>
                        <li data-target="#demo" data-slide-to="1"></li>
                        <li data-target="#demo" data-slide-to="2"></li>
                    </ul>
                    <div class="carousel-inner">
                        <div class="carousel-item active">
                            <img src="slide1.jpg" alt="Los Angeles" width="1100" height="500">
                            <div class="carousel-caption">
                                <h3>The Classic Sandwhich</h3>
                                <p>Your tastebuds will love this thing!</p>
                            </div>   
                        </div>
                        <div class="carousel-item">
                            <img src="slide2.jpg" alt="Chicago" width="1100" height="500">
                            <div class="carousel-caption">
                                <h3>Crispy</h3>
                                <p>You will love how we deep fry it!</p>
                            </div>   
                        </div>
                        <div class="carousel-item">
                            <img src="slide3.jpg" alt="New York" width="1100" height="500">
                            <div class="carousel-caption">
                                <h3>Ohh Fancy...</h3>
                                <p>Come try our new BBQ Chicken</p>
                            </div>   
                        </div>
                    </div>
                    <a class="carousel-control-prev" href="#demo" data-slide="prev">
                        <span class="carousel-control-prev-icon"></span>
                    </a>
                    <a class="carousel-control-next" href="#demo" data-slide="next">
                        <span class="carousel-control-next-icon"></span>
                    </a>
                </div>


            </div>

            <div class="row" id="chickenTopRow">
                <div class="col-sm-4 offset-sm-1">
                    <img src="box1.jpg" class="img-fluid">
                    <h1 class="textOnImage">100% Fresh</h1>
                </div>

                <div class="col-sm-4 offset-sm-2">
                    <img src="box4.jpg" class="img-fluid">
                    <h1 class="textOnImage">Hand Made</h1>
                </div>

            </div>

            <div class="row" id="chickenBottomRow">
                <div class="col-sm-4 offset-sm-1">
                    <img src="box3.jpg" class="img-fluid">
                    <h1 class="textOnImage">All Natural</h1>
                </div>

                <div class="col-sm-4 offset-sm-2">
                    <img src="box2.jpg" class="img-fluid">
                    <h1 class="textOnImage">Tasty</h1>
                </div>

            </div>

            <div class="row text-center">

                <h1 class="phoneColumn"><i class="fas fa-phone-volume fa-1x"></i>
                    Order Now    <i class="fas fa-phone-volume fa-1x"></i></h1>
                <br>
                <h1 class="phoneColumn">281-330-8400</h1>

            </div>


            <div class="row" id="#mapRow">

                <div id="map"></div>
            </div>



        </div>

        <script>
            // Initialize and add the map
            function initMap() {
                // The location of Uluru
                var uluru = {lat: -25.344, lng: 131.036};
                // The map, centered at Uluru
                var map = new google.maps.Map(
                    document.getElementById('map'), {zoom: 4, center: uluru});
                // The marker, positioned at Uluru
                var marker = new google.maps.Marker({position: uluru, map: map});
            }
        </script>

        <script async defer
                src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY&callback=initMap">
        </script>



        <!-- Optional JavaScript -->
        <!-- jQuery first, then Popper.js, then Bootstrap JS -->
        <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
        <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
    </body>
</html>

Here is code of my CSS

#logo{
    font-family: 'Vibur', cursive;
}

.carousel-item img {
  width: 100vw;
  height: 100%;
}

.textOnImage{

    position: absolute;
    width: 100%;
    text-align: center;
    top: 50%;
    color: white;

}

#chickenTopRow{
    padding-top: 20px !important;
    padding-bottom: 20px !important;
}

#chickenBottomRow{
    padding-bottom: 20px;
}

.phoneColumn{
    display: block;
    width: 100%;
}



#map{
    height: 400px;

}

I just inspected and changed the #map div width to 100% in the style sheet and it fixed the problem. It was trial and error and I am still not able to understand the issue.

Can someone help me?

Thanks,

evan
  • 4,435
  • 2
  • 5
  • 15
benz
  • 4,171
  • 6
  • 31
  • 55
  • I inspected and added the css in #map as width:100% and it did the magic. Still figuring out the issue though. I am very new to CSS. – benz Jan 13 '20 at 01:11
  • This question might be useful: https://stackoverflow.com/questions/29983786/blocked-a-frame-of-origin-null-from-accessing-a-cross-origin-frame-chrome – Mohamed Farouk Jan 13 '20 at 01:22
  • This is not relevant to what i asked mate. – benz Jan 13 '20 at 02:55
  • I've removed your API key from your question. Please don't share private API keys on public sites, and make sure you restrict them as per https://developers.google.com/maps/api-key-best-practices#restrict_apikey – evan Jan 15 '20 at 09:57

0 Answers0