Error loading Google Maps in Bootstrap 3.0 modal due to incomplete loading

Embedding the jQuery location picker into the content box of a Bootstrap modal 3 can be done like this:

HTML:

<a data-toggle="modal" href="#myModal" class="btn btn-primary">Launch modal</a>

        <div class="modal" id="myModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                         <h4 class="modal-title">Modal title</h4>

                    </div>
                    <div class="modal-body">Location:
                        <input type="text" id="us2-address" style="width: 200px" />Radius:
                        <input type="text" id="us2-radius" />
                        <div id="us2" style="height: 400px;"></div>Lat.:
                        <input type="text" id="us2-lat" />Long.:
                        <input type="text" id="us2-lon" />
                    </div>
                    <div class="modal-footer"> <a href="#" data-dismiss="modal" class="btn">Close</a>
             <a href="#" class="btn btn-primary" id="save-changes">Save changes</a>

                    </div>
                </div>
            </div>
        </div>
    

However, it seems that when loading the Google map within the modal (by clicking "Launch modal"), it does not load completely and only shows part of it.

NOTE: Resizing the browser window causes the map to load properly.

You can see an example in the following link :

DEMO : http://jsfiddle.net/Lzv7w/3/

Any suggestions on how to resolve this issue?

Answer №1

One method is as follows:

To set up the map, you need to initialize it when the modal is first displayed...

Example : http://jsfiddle.net/Lzv7w/8/

Javascript :

var stillPresent = false;
$('#myModal').on('shown.bs.modal', function (e) {
        if(stillPresent == false){
               $('#us2').locationpicker({
            location: {
                latitude: 46.15242437752303,
                longitude: 2.7470703125
            },
            radius: 300,
            inputBinding: {
                latitudeInput: $('#us2-lat'),
                longitudeInput: $('#us2-lon'),
                radiusInput: $('#us2-radius'),
                locationNameInput: $('#us2-address')
            }
        });
         stillPresent = true;
        }
    })

Answer №2

Dealing with a similar issue of loading a map inside a tab, the solution required calling .locationpicker when the tab is clicked. Below is an example demonstrating how to resolve this problem:

$( "#map_container" ).click(function() {
     $('#us3').locationpicker({
         location: {latitude: 35.770681, longitude: 10.828099},
         radius: 300,
         inputBinding: {
             latitudeInput: $('#us3-lat'),
             longitudeInput: $('#us3-lon'),
             radiusInput: $('#us3-radius'),
             locationNameInput: $('#us3-address')
         },
         enableAutocomplete: true,
         onchanged: function (currentLocation, radius, isMarkerDropped) {
         }
     });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing a jQuery datepicker to dynamically populate future dates from JSON data

Looking for a jQuery datepicker that can read JSON data... I have a list of upcoming dates for each month in my JSON file that I want the datepicker to disable and highlight with a specific color. ...

Problem encountered on WordPress involving a hyperlink division and a themed backdrop

Currently, I am a student studying web development and assisting a friend with adding custom links and a slider to her WordPress website. The issue we are encountering is that the original developer who created her website six years ago did not set up a ch ...

When the button is clicked, jQuery refreshes the webpage

I have a get route that returns a view with data. Within this view, there is a form using LaravelCollective's HTML package. The form includes a button, which is not the submit button but triggers a click event via jQuery. This event appends elements t ...

Validate if a variable is present in a JSON object

I am currently facing an issue that I cannot solve on my own, so I would greatly appreciate any assistance. The problem I am encountering involves a dynamic cart that is populated with JSON data. The shipping costs in the cart are also filled from the sam ...

The localization feature in jQuery mobile is causing the button style to disappear

For my current project, I am utilizing the jquerymobile framework along with the i18Next localization library. Here is the HTML code snippet: <div id="messageboxPage" data-role="page" data-theme="a"> &l ...

Trouble with Bootstrap 5 Dropdown Menu failing to drop down

I am attempting to utilize a dropdown menu on my Wordpress site with Bootstrap, but it is not working as expected. If I manually add the class "show" to my dropdown-menu div, the menu displays, but the button does not function. These are the scripts being ...

tips for sending the database value to the next page with ajax

Struggling to send the database value retrieved through ajax to the next page. Tried several methods but none seem to work. Could anyone provide guidance on how to achieve this? php Successfully connected to the database $sql = "SELECT * FROM `billin ...

Forced line break at particular point in text

I would love to implement a line break right before the "+" character, either using css styling or through a different method. Is this task achievable? #myDiv{ width: 80% } #myP{ c ...

Simple steps for integrating JavaScript ads into your WordPress website

Received an advertisement from my client, a 300x250 ad in ad folder consisting of 1 HTML file, 1 JavaScript file, and 1 images folder. Questioning how to integrate these files into the side panel of my Wordpress website's homepage. I've spent a ...

Arrange the side by side display of uploaded image previews

Could someone please assist me with aligning my image upload preview in a row, similar to a brand/partners slider? The current preview output is not displaying as desired. Here is the code I have: <div class="image-gallery"> <div class ...

Tips for properly using the :after pseudo-element with styled components in React.js

Recently, I came across this intriguing underline animation: <ul> <li><a href="#">About</a></li> <li><a href="#">Portfolio</a></li> <li><a href="#">Blog&l ...

Scroll downwards to reveal the hidden div element on an HTML page

How can we implement a Snapchat-inspired feature in a web application using AngularJS? The idea is to have a div appear when the user scrolls down or pulls the screen down, and then have it pushed back up when they scroll back up. This functionality is si ...

Utilize the HTML5 datepicker with jQuery to set minimum and maximum dates and

I recently created a function to specify minimum and maximum dates for a datepicker, as well as format the selected date. However, I noticed that when I set the date range, the format reverts back to the default mm/dd/yy. It's important to mention tha ...

The impact of adjusting the article's margin-top on the margin-top of

I want these two divs to have different positioning. The sidebar should remain fixed at the top. Why is the sidebar aligned with the article div instead of sticking to the top? body{ margin: 0; padding: 0; } div#sidebar{ background-color: yel ...

CSS navigation issue

When using the third example provided on this page: http://simple-navigation-demo.andischacke.com/ I encountered an issue where the main page would display an empty div on the left instead of the content filling the entire area. However, when navigating ...

How can I remove the clear and "step" buttons from the Jquery Datepicker?

Recently, I took over a project from a client who no longer wants the "clear" buttons and the date increment "step" to be displayed. I have been struggling to remove these elements as they seem to be embedded within the input field itself, rather than bein ...

Tips on preventing the entire HTML structure from being displayed on my <div> element after an Ajax success(response) call

I have successfully implemented a user logon system on my website with flawless code execution. Check out the reset password Ajax request below. html <div id="forgotPass"></div> <script type="text/javascript"> ...

"Implementing a responsive design with a background image and radial gradient - how to

The image currently in use: https://i.stack.imgur.com/piK6l.jpg Here is how I've implemented it using Vue.js, Bootstrap, and CSS: Code Snippet <div class="landing"> <div class="container text-white details h-100"> ...

Updating an SVG after dynamically adding a group with javascript: a step-by-step guide

Currently, I am working on a circuit builder project using SVG for the components. In my HTML structure, I have an empty SVG tag that is scaled to full width and height. When I drag components from the toolbar into the canvas (screen), my JavaScript functi ...

Display the quantity of stock in WooCommerce as separate numerical values

I am looking to display the stock quantity of products on a specific page of my website. The code I am currently using to retrieve the stock quantity is as follows: <p class="stock-m13"><?php echo $product->get_stock_quantity(); ?></p> ...