簡體   English   中英

Google Map未在jquery mobile中加載

[英]Google map didn't load in jquery mobile

我不知道為什么當我嘗試在我的應用程序上顯示地圖時不起作用..只是灰色,但是當我在Jsfiddle上運行它時,一切都很好。 我認為這與頁面顯示有關,如果我將其更改為pageinit,則地圖未完全加載,並且我將所有高度和寬度都更改為100%,但仍未完全加載。

<html lang="en">
  <head>
    <title>Maps</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
    <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"> </script>
    <script type="text/javascript">


        var map;

        function initialize()
        {
            map = new google.maps.Map(document.getElementById('map_canvas'), {
               zoom: 7,
               center: new google.maps.LatLng(38.0457918, 23.7676337),
               mapTypeId: google.maps.MapTypeId.ROADMAP
             });
            var currentPositionMarker = new google.maps.Marker({
                    position: new google.maps.LatLng(38.0457918, 23.7676337),
                    map: map,
                    title :"hei"
                });
        }


        $(document).on("pageshow", "#basic-map", function() {
            initialize();
        });


    </script>
</head>
<body>
    <div id="basic-map" data-role="page">
        <div data-role="header">
            <h1><a data-ajax="false" href="/">examples</h1>
        </div>
        <div data-role="content"> 
            <p>this is paragraph</p>
              <ul data-role="listview" data-inset="true" data-divider-theme="b">
                  <li data-role="list-divider">Map</li>
                  <div id="map_canvas" style="height:320px;"></div> 
                </ul>

        </div>
    </div>      
</body>
</html>

我確實嘗試添加此代碼,但地圖已完全加載,但標記未居中。

$( document ).bind( "pageshow", function( event, data ){
google.maps.event.trigger(map, 'resize');
});

第二件事是標題標記未顯示。 請幫助..謝謝

觸發調整大小事件后,重置地圖的中心位置。

$( document ).bind( "pageshow", function( event, data ){
  google.maps.event.trigger(map, 'resize');
  map.setCenter(currentPositionMarker.getPosition());
});

(像map變量一樣使currentPositionMarker全局變量之后)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM