samedi 28 février 2015

Google maps not full size unless you refresh page


I am using jquery mobile to create a webpage and I followed the tutorial found here: http://ift.tt/1N3qLfo Basically in a nutshell the video is about adding multiple markers on a google maps and then making sure all the markers are shown on the map at the same time.


MY problem is that when i load the page whether on my phone or my computer the map is not the correct size BUT the height and width of what the map SHOULD be is visible


Now if i refresh the page the map becomes full size.


I am just guessing but maybe the page is loading without finishing loading the google maps api BUT i am just guessing


Here is the code I used to create the map



function init() {
var mapDiv = document.getElementById("map_canvas3");
var mapOptions = {
center: new google.maps.LatLng(48.8582, 2.2945),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(mapDiv, mapOptions);

var locations = [];
locations.push ( {name:"Eifel Tower", latlng: new

google.maps.LatLng(48.8582, 2.2945)} );
locations.push ( {name:"The Louvre", latlng: new

google.maps.LatLng(48.8611, 2.3364)} );

var bounds = new google.maps.LatLngBounds ();
for (var i=0;i<locations.length;i++ ) {
var marker = new google.maps.Marker({position: locations[i].latlng,

map:map, title:locations[i].name});
bounds.extend (locations[i].latlng);

}
map.fitBounds (bounds);

}
window.onload = init;


Here is the html



<div data-role="page" id="mapEiffelTower" >

<div data-role="header">
<a href="#homePage" class="ui-btn-left ui-btn ui-icon-back ui-

btn-icon-notext ui-shadow ui-corner-all" data-role="button"

role="button">Back</a>
<img src="assets/Logo-01.png" id="logoHeader" alt="logo"/>
<!--<a href="index.html" class="ui-btn ui-icon-bars ui-btn-icon-

notext "></a>-->


</div> <!--end of header-->

<div data-role="content" >
<div id="map_canvas3">
</div>

</div> <!-- end of content -->



</div> <!-- end of mapEiffelTower page -->


And here is what it looks like for me now


!http://ift.tt/1LXES4n


Is there a line of code that I can enter to fix this problem?





Aucun commentaire:

Enregistrer un commentaire