我想一個谷歌地圖添加到我的Android平板電腦,以檢測其中is.But地圖終端沒有完全顯示。只顯示了一小部分。旋轉屏幕後,可以完美顯示。 我做這一切根據http://www.digitalnoiz.com/mobile-development/geolocation-jquery-mobile-maps/ 這是我的html代碼:谷歌地圖顯示不完全在Android平板電腦
<head>
<link href='stylesheets/jquery.mobile-1.1.0.css' rel='stylesheet' />
<link href='stylesheets/my.css' rel='stylesheet' />
<script charset='utf-8' src='javascripts/jquery/jquery-1.7.1.min.js' type='text/javascript'></script>
<script charset='utf-8' src='javascripts/jquery.ui.map.min.js' type='text/javascript'></script>
<script charset='utf-8' src='http://maps.google.com/maps/api/js?sensor=true' type='text/javascript'></script>
<script charset='utf-8' src='javascripts/application.js' type='text/javascript'></script>
<script charset='utf-8' src='javascripts/jquery/jquery.mobile-1.1.1.js' type='text/javascript'></script>
<script type="text/javascript" charset="utf-8" src="javascripts/phonegap/cordova-2.0.0.js"><\/script>
</head>
<body>
<!-- Diagnostic -->
<div data-role='page' id='diagnostic_page'>
<div data-position='inline' data-role='header' data-theme='a'>
<h2>
Diagnostic
</h2>
<a data-icon='arrow-l' href='#index_page'>
Back
</a>
<a data-role='button' href='#diagnostic_page' id='PageRefresh'>
Refresh
</a>
</div>
<div data-role='content' style='padding: 15px'>
<ul data-divider-theme='a' data-inset='true' data-role='listview'>
<!--there are some other list variables-->
<li data-theme='c'>
Show current location:
<a class='classspan' href='#location_page'>
Click on me
</a>
</li>
</ul>
</div>
</div>
<!-- show current location -->
<div data-role='page' data-theme='c' id='location_page'>
<div data-position='fixed' data-role='header' data-theme='a'>
<a data-icon='arrow-l' href='#diagnostic_page'>
Back
</a>
<h2>
DigitalNoiz
</h2>
<div data-role='header'></div>
Geolocation
<div id='map_canvas'></div>
<div id='geolocation'></div>
</div>
</div>
</body>
這是我的jQuery代碼,我所有的功能代碼在application.js中編輯。
function onLoad() {
console.log('Init reached');
$.mobile.allowCrossDomainPages = true;
$.mobile.showPageLoadingMsg();
$.support.cors = true;
document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
console.log('Starting up...');
// navigator.app.overrideBackbutton(true);
document.addEventListener("backbutton", onBackKeyDown, false);
console.log('Initializing db');
refreshpage();
getPosition();
}
function getPosition(){
var geoOptions = { enableHighAccuracy: true, timeout: 10000 };
navigator.geolocation.getCurrentPosition(function(position){ // geoSuccess
// we have the position
var geolocation = $('#geolocation');
geolocation.html('<table></table>');
var table = geolocation.find('table');
if(position.coords.latitude)
table.append('<tr><th>Latitude</th><td>' + position.coords.latitude + '</td></tr>');
if(position.coords.longitude)
table.append('<tr><th>Longitude</th><td>' + position.coords.longitude + '</td></tr>');
if(position.coords.altitude)
table.append('<tr><th>Altitude</th><td>' + position.coords.altitude + '</td></tr>');
if(position.coords.accuracy)
table.append('<tr><th>Accuracy</th><td>' + position.coords.accuracy + '</td></tr>');
if(position.coords.altitudeAccuracy)
table.append('<tr><th>Altitude Accuracy</th><td>' + position.coords.altitudeAccuracy + '</td></tr>');
if(position.coords.heading)
table.append('<tr><th>Heading</th><td>' + position.coords.heading + '</td></tr>');
if(position.coords.speed)
table.append('<tr><th>Speed</th><td>' + position.coords.speed + '</td></tr>');
if(position.coords.timestamp)
table.append('<tr><th>Timestamp</th><td>' + new Date(position.timestamp) + '</td></tr>');
//show position on map
var map_canvas = $('#map_canvas');
map_canvas.gmap(
{'center' : position.coords.latitude + ',' + position.coords.longitude,
'zoom' : 12,
'disableDefaultUI':true,
'callback':function(){
var self = this;
var marker = self.addMarker({ 'position' : this.get('map').getCenter() });
marker.click(function(){
self.openInfoWindow({ 'content' : 'This is your current location' }, this);
});
}
});
}, function(error){ // geoError
navigator.notification.alert('error: ' + error.message + '\n' + 'code: ' + error.code);
}, geoOptions);
}
任何人都可以給我一些建議嗎?
我給了我一個大小#map_canvas { 寬度:100%; height:600px; margin-bottom:10px; }但它仍然沒有工作。 – HuaY
不是百分比!寬度:100%是什麼? – Marcelo
100%的屏幕。我希望地圖能夠調整到屏幕,即使它被渲染。 – HuaY