When showing a google map in jquery mobile it appears (after reading the forums) that code like the following is required:
<div data-role="page" data-theme="b" class="page-map" style="width:100%; height:100%;">
<div data-role="header"><h1>Map Page</h1></div>
<div data-role="content" style="width:100%; height:100%; padding:0;">
<div id="map_canvas" style="width:100%; height:100%;"></div>
</div>
</div>
Taking away the height on outside div causes the div to drop to height 0 and the map not being displayed. I was hoping to get some dynamic text below the map (based on the contents on the) which length I do not know so I can't set an absolute height. Has anyone got a workaround for this problem?
This is not a Google maps related issue, the thing is, you need to SET a specific width and height for your Map canvas, your code could be rewritten like:
<div data-role="page" data-theme="b" class="page-map" style="width:100%; height:100%;">
<div data-role="header"><h1>Map Page</h1></div>
<div data-role="content" style="padding:0;">
<div id="map_canvas" style="width:300px; height:300px;"></div>
<p id="text">Lorem ipsum legere facilisi conclusionemque pro et, sint aperiam vel at. No postea scaevola vivendum duo, et vix erant paulo. Ex fuisset perfecto vix. No sit laudem noster scriptorem, probatus assueverit ius cu.</p>
</div>
</div>
Example link
UPDATE: Have a look @Blowsie comment, you may also check the jquery-ui-map plugin.
There is an official example for this here: http://view.jquerymobile.com/master/demos/examples/maps/geolocation.php
HTML:
<div data-role="page" class="page-map">
<script src="map.js"></script>
<link rel="stylesheet" href="map.css" />
<div data-role="header"><h1>Map View</h1></div>
<div data-role="content">
<div id="map-canvas">
<!-- map loads here... -->
</div>
</div>
</div>
CSS:
.page-map, .ui-content, #map-canvas { width: 100%; height: 100%; padding: 0; }
Well here how I did it and it worked for me.
<div data-role="page" id="atm" data-theme="b">
<div data-role="header" data-theme="b" data-position="inline" class="classHeader">
<a href="#home" data-icon="home" data-iconpos="notext" data-direction="reverse" class="ui-btn-left jqm-home">Options</a>
<h1>Location</h1>
</div>
<div data-role="content" id="map_canvas"></div>
<div data-role="footer" data-position="fixed" data-theme="b" class="classFooter">
<h1>Copyright © 2011.</h1>
</div>
</div>
Then add these to your CSS File.
.classHeader{
height:10% !important;
}
.classFooter{
height:10% !important;
}
#map_canvas{
padding-top:10%;
padding-bottom:10%;
height:auto;
position:absolute;
width:100%;
height:88%;
max-height:1600px;
overflow:hidden;
display:block;
}
This is working perfectly for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With