我一直在使用此代码在 jquery 移动页面显示事件中显示谷歌地图,但它不起作用..
$('#page3').live('pageshow', function(event, ui) {
$('#googleMap').gmap().bind('init', function(ev, map) {
$('#googleMap').gmap('addMarker', {'position': '57.7973333,12.0502107', 'bounds':
true}).click(function() {
$('#googleMap').gmap('openInfoWindow', {'content': 'Hello World!'}, this);
});
});
});
最佳答案
我认为这个解决方案可以解决您的问题:
您的map.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Map</title>
<script>
function initialize() {
var myLatlng = new google.maps.LatLng( 51.520838, -0.140261 );
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map( document.getElementById( "map_canvas" ), myOptions );
}
</script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<style>
html {
height: 100%;
overflow: hidden;
}
body {
margin: 0;
padding: 0;
height: 100%;
}
#map_canvas {
height: 100%;
}
</style>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
打开map.html的按钮
<div data-role="popup" id="popupMap" data-overlay-theme="a" data-theme="a" data-corners="false" data-tolerance="15,15">
<a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right">Close</a>
<iframe src="map.html" width="480" height="320" seamless></iframe>
</div>
查看有关 jQuery Mobile - Popup iframes 的更多信息
关于页面上的 jquery 和 google map 显示事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13970571/