Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Map API v3 off center if reloaded (not the usual 'resize' thing)
    primarykey
    data
    text
    <p>I read all the similar questions but mine is slightly different. The first time a JQuery Mobile dialog is displayed, the map loads fine inside the usual map_canvas div, but if the dialog is reloaded (i.e. go back and click on the button to open the dialog again), it is displayed only partially, zoomed out to a 3 or 4 and centered around the div's top-left corner.</p> <p>There is no change in the div size (which is explicitly set) and for good measure a <code>google.maps.event.trigger(map, 'resize');</code> is called.</p> <p>I also tried to initialize the map <strong>after</strong> the dialog is shown but the result is the same.</p> <p>Button code:</p> <pre><code>$("#dest-map-button").click(function() { initializeMap(job_id,"map_canvas"); } ); </code></pre> <p>Function:</p> <pre><code>function initializeMap(job_id, map_div){ var pos = arrJobs[job_id].lat_lng.split(','); var job_pos = new google.maps.LatLng(pos[0],pos[1]); var driverLatLng = lat_lng.split(','); var driver_pos = new google.maps.LatLng(driverLatLng[0],driverLatLng[1]); var myOptions = { zoom: 18, center: driver_pos, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true } map = new google.maps.Map(document.getElementById(map_div), myOptions); var marker = new google.maps.Marker({ position: job_pos, map: map, title: "Job" }); var marker2 = new google.maps.Marker({ position: driver_pos, map: map, title: "X", }); google.maps.event.trigger(map, 'resize'); } </code></pre> <p>HTML:</p> <pre><code> &lt;div data-role="page" id="dialog-destination-map" data-theme="e"&gt; &lt;div data-role="content"&gt; &lt;div id="map_canvas" style="height:300px; width:300px; position: relative; margin: 0px auto;"&gt; map_canvas &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Any ideas?</p> <p>EDIT: this question seems describing exactly the same problem: <a href="https://stackoverflow.com/questions/8918197/jquery-mobile-google-maps-glitch">JQuery Mobile &amp; Google Maps Glitch</a> But the solution provided (caching) can't be used here as the map might need to change</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.
 

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