Google map modal issue

前端 未结 10 1360
别那么骄傲
别那么骄傲 2020-12-11 02:48

I am trying to display google map into the Twitter bootstrap modal. When user first click on the button Show map then he is able to see the map successfuly as i

相关标签:
10条回答
  • 2020-12-11 03:32

    I will use uiGmapIsReady wait the dom ready then force the map resize:

    uiGmapIsReady.promise().then(function () {
        var map = $scope.map.control.getGMap();
        google.maps.event.trigger(map, 'resize');
    });

    0 讨论(0)
  • 2020-12-11 03:35

    The visibility:hidden and visibility:visible could be used instead of display:none and display:block. This worked for me. You can even edit the CSS of the modal for this.

    0 讨论(0)
  • 2020-12-11 03:37

    well this is how the answers above helped but I had to call the main function using onclick .

    <span data-target="#enlargeModal"data-toggle="modal" onclick="newMap()" class="fa fa-expand r"></span>
    
    function newMap()
    

    {

    function showMap() {

    //your map function
    

    }

        $('#enlargeModal').on('shown.bs.modal', function () {
              var center = fullmap.getCenter();
              google.maps.event.trigger(fullmap, 'resize');
              fullmap.setCenter(center);
        });
    

    showMap(); }

    0 讨论(0)
  • 2020-12-11 03:39

    I had the same issue. but I found an issue with modal shown event. as its not working with some version of issue so I just follow the bootstrap modal documentation to achieve it.

    Bootstrap Modal Map Issue Solution :

    $(document).ready(function(){
      $('#locationMap').on('shown.bs.modal', function(){
        google.maps.event.trigger(map, 'resize');
        map.setCenter(new google.maps.LatLng(-33.8688, 151.2195));
      });
    });
    

    Finally This works for me, It could help to someone.

    0 讨论(0)
提交回复
热议问题