Google map not filling modal popup

前端 未结 5 521
心在旅途
心在旅途 2021-01-14 10:46

I\'m using a modal popup when users click the map on this page here, which brings up a larger map with directions.

The map isn\'t filling the entire space however an

相关标签:
5条回答
  • 2021-01-14 11:16

    Thanks for the answers guys. Just to help anyone else that may have this problem, in addition to having to resize due to having the map in a modal, I also had to reset the center.

    The below code needed to be added within the initialize function.

        $('#show_map').on('shown', function () {
            google.maps.event.trigger(map, "resize");
            map.setCenter(myLatlng);
        });
    
    0 讨论(0)
  • 2021-01-14 11:23
    $('#Map_Modal_ID').on('shown.bs.modal', function () {
        initialize();
    });
    
    0 讨论(0)
  • 2021-01-14 11:30

    For completeness: if you're using Bootstrap modal window you need to use shown.bs.modal event in place of shown event.

    Here the code:

      $("#modalWindowId").on("shown.bs.modal", function(e) {
        google.maps.event.trigger(map, "resize");
        map.setCenter(markerLatLng); // Set here center map coordinates
      });
    

    Take a look here for learn more: http://coderpills.wordpress.com/2014/06/02/showing-google-map-inside-a-bootstrap-modal-window/

    0 讨论(0)
  • 2021-01-14 11:35

    You can trigger a resize event on the map, after the modal is launched, which will cause it to resize to fit the dimensions of the containing div. From the documentation:

    Developers should trigger this event on the map when the div changes size

    // Add this at the bottom of the script which defines your map
    // It will trigger the resize event on the map after the modal has launched
    $('#myModal').on('shown', function () {
      google.maps.event.trigger(map, 'resize');
    })
    

    I think when you launch dev tools the window.onResize event is causing the resize event to be triggered on the map. You can prove this by detaching dev tools from the browser window before clicking your modal.

    0 讨论(0)
  • 2021-01-14 11:35

    Try to use this

    padding: 0;

    Css:

    .modal-body {
    max-height: 400px;
    overflow-y: auto;
    padding: 0;
    position: relative;
         }
    
    0 讨论(0)
提交回复
热议问题