Note that there are some explanatory texts on larger screens.

plurals
  1. POgoogle maps not displayed correctly unless refreshing
    primarykey
    data
    text
    <p>I am using JQuery mobile with the Google Map API. The map is not displayed properly unless I refresh the page and I don't understand why.</p> <p>here is my map.html file:</p> <pre><code>&lt;div data-role="page" id="map-page"&gt; &lt;div data-role="content" id="canvas-map" style="background-color:red"&gt;&lt;/div&gt; &lt;script src="js/map.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var $canvasMap = $('#canvas-map'); $('#canvas-map').on('pagebeforeshow', initMap()); &lt;/script&gt; &lt;/div&gt; </code></pre> <p>and my map.js file:</p> <pre><code>function initMap() { "use strict"; google.maps.visualRefresh = true; var marker, map, myLocation = {lat:50, lon:-80}, mapOptions = { zoom: 5, center: new google.maps.LatLng(myLocation.lat, myLocation.lon), mapTypeId: google.maps.MapTypeId.PLAN, disableDefaultUI: true }; $('#canvas-map').css("height", "200px").css("padding", "0px"); map = new google.maps.Map(document.getElementById('canvas-map'), mapOptions); /** MyPosition **/ marker = new google.maps.Marker({ map: map, draggable: false, animation: google.maps.Animation.DROP, position: new google.maps.LatLng(myLocation.lat, myLocation.lon), }); } </code></pre> <p>If I navigate from another page to the above page, I get the following result: <img src="https://i.stack.imgur.com/iAOqv.jpg" alt="broken google maps"></p> <p>And then when I refresh, I get the expected result: <img src="https://i.stack.imgur.com/kZkXJ.jpg" alt="refreshed google maps working fine"></p> <p>It is obviously not a problem with the canvas, since it is displayed (in red). Plus,if I navigate trhough the map, I can see the marker displayed at the right position. These screenshots were made using Google Chrome, I tried with Firefox and the canvas is here completely red, no map at all.</p> <p>PS: this is a simple version of my original code, but the behavior is the same.</p> <h2>EDIT:</h2> <p>See Gajotres' answer for details, but basically, within the link to access map.html page, adding <code>target="_blank"</code> solved the issue. Note that <code>target="_self"</code> seems to work as well, strange since it is supposed to be the default value. Details on <strong>target</strong> <a href="http://www.w3.org/TR/html4/types.html#h-6.16" rel="nofollow noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload