页面上的 jquery 和 google map 显示事件

标签 jquery jquery-ui jquery-mobile google-maps-api-3

我一直在使用此代码在 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/

相关文章:

javascript - 可放置元素的位置计算不正确

javascript - 悬停文本颜色上的jquery ui Accordion

jquery - 动态创建按钮 - JQueryMobile

jquery - 交错图像和输入字段的问题

jquery - 检测 jQuery UI 自动完成

javascript - CSS 中的砖 block 布局

javascript - 如何在 JQM 中为不同页面制作页码页眉

jQuery 手机 “Error Loading Page”

javascript - toFixed 方法不适用于用户输入,但适用于 javascript 中的其他变量,包括代码片段

javascript - 为什么 jQuery 事件在我使用由 jQuery 生成的类时不起作用