Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Google Map cannot be displayed Inside Bootstrap Modal View

javascript google-map

  • Please log in to reply
No replies to this topic

#1 mutago


    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 478 posts

Posted 31 January 2017 - 07:41 PM

Hi everyone, the code below displays a google map when run directly from a page but when embedded inside a bootstrap modal view, the google map content will not be displayed. only the map blank shape is showed. can someone help me with that. Thanks


<!DOCTYPE html>
<html lang="en">
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script src="http://maps.google.com/maps/api/js?libraries=places&region=ng&language=en&sensor=true&key=AIzaSyAlb3bRgk_Jq3mBzgpVyLTeeKL-RKaSkx4"></script>


<div class="container">
  <h2>Google Map</h2>
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open MAP</button>

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        <div class="modal-body">
    <br> Address:

  <input id="searchTextField" type="text" size="50" style="">

  <div id="test" style="height: 300px;width: 100%;margin: 0.6em;"></div>
  <!-- MAP -->
  <script type="text/javascript">
    $(function getMap() {
      var lat = 13.034118,
        lng = 77.5679959;
      latlng = new google.maps.LatLng(lat, lng),
        image = 'http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png';

      //zoomControl: true,
      //zoomControlOptions: google.maps.ZoomControlStyle.LARGE,

      var mapOptions = {
          center: new google.maps.LatLng(lat, lng),
          zoom: 13,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          panControl: true,
          panControlOptions: {
            position: google.maps.ControlPosition.TOP_RIGHT
          zoomControl: true,
          zoomControlOptions: {
            style: google.maps.ZoomControlStyle.LARGE,
            position: google.maps.ControlPosition.TOP_left
        map = new google.maps.Map(document.getElementById('test'), mapOptions),
        marker = new google.maps.Marker({
          position: latlng,
          map: map,
          icon: image

      var input = document.getElementById('searchTextField');
      var autocomplete = new google.maps.places.Autocomplete(input, {
        types: ["geocode"]

      autocomplete.bindTo('bounds', map);
      var infowindow = new google.maps.InfoWindow();

      google.maps.event.addListener(autocomplete, 'place_changed', function(event) {
        var place = autocomplete.getPlace();
        if (place.geometry.viewport) {
        } else {

        moveMarker(place.name, place.geometry.location);
      google.maps.event.addListener(map, 'click', function(event) {
        var geocoder = new google.maps.Geocoder();
          "latLng": event.latLng
        }, function(results, status) {
          console.log(results, status);
          if (status == google.maps.GeocoderStatus.OK) {
            var lat = results[0].geometry.location.lat(),
              lng = results[0].geometry.location.lng(),
              placeName = results[0].address_components[0].long_name,
              latlng = new google.maps.LatLng(lat, lng);

            moveMarker(placeName, latlng);

      function moveMarker(placeName, latlng) {
        //infowindow.open(map, marker);
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download