谷歌地图没有在我的 jQuery 移动弹出窗口上绘制? [复制]

Posted

技术标签:

【中文标题】谷歌地图没有在我的 jQuery 移动弹出窗口上绘制? [复制]【英文标题】:Google maps doesn't draw on my jQuery mobile popup? [duplicate] 【发布时间】:2014-01-12 19:05:45 【问题描述】:

我有一些业务,我想在地图上绘制它们

我构建了函数 setupMap(x,y),因为 x 是纬度,y 是经度。

由于某种原因,它什么也没画。

当我点击show map 按钮时:

<a onclick="setupMap('33.23478899909723', '35.57791471481323')"  href='#showMap' data-inline='true' data-mini='true' data-role='button' data-rel='popup' data-position-to="window" data-transition="pop" >Show on map</a>

jQuery mobile 对话框打开,但未绘制任何内容。 (甚至没有ccc

应该绘制地图。

完整代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="ISO-8859-1">
        <title>CoCouppn!</title>
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
        <script type="text/javascript">
            $(document).on("pageshow", function() 
                $.post("loadUserCoupons", cat: "billie", function(data) 
                );
            ); // jquery end

            function setupMap(x, y) 
                var map;
                var loc = new google.maps.LatLng(x, y);
                var ops = 
                    zoom: 15,
                    center: loc
                ;

                map = new google.maps.Map(document.getElementById("heresTheMap"), ops);

                // Mark the business
                google.maps.event.addListenerOnce(map, 'idle', function() 
                    new google.maps.Marker(
                        position: loc,
                        map: map
                    );
                );
            

            // Get user location
            var userX = 0, userY = 0; // default x,y in case of deny
            var hasLocationSet = false;

            function setUserLocation() 
                if(navigator.geolocation) 
                    navigator.geolocation.getCurrentPosition(function(pos) 
                        userX = pos.coords.latitude;
                        userY = pos.coords.longitude;
                        hasLocationSet = true;
                    , function() 
                        alert("Warning: we must have your location! until then, all coupons will be shown. ")
                    );
                
            
        </script>
    </head>
    <body onload="setUserLocation()">   
            <div data-role="page">
                <div data-role="header" data-theme="b">
                    <h1>Choose food coupon</h1>
                </div>

                <!-- slider for coupons distance -->

                <label for="slider-fill">Max coupon distance: </label>
                <input type="range" name="slider-fill" id="slider-fill" value="10" min="1" max="100" data-highlight="true" />

                <table id="showcoupons" data-role="table" data-mode="column">
                    <thead style="background-color: #DDD; font-weight: bold;">
                        <td>Img</td>
                        <td>details</td>
                        <td>ends</td>
                        <td>location</td>
                    </thead>

                    <tbody>

                            <tr>
                                <td>  </td>
                                <td>Take yourself to higher places! </td>
                                <td>2014-01-02 at 11:11 </td>
                                <td><a onclick="setupMap('33.2358409066188', '35.578086376190186')"  href='#showMap' data-inline='true' data-mini='true' data-role='button' data-rel='popup' data-position-to="window" data-transition="pop" >Show on map</a></td>
                            </tr>

                            <tr>
                                <td>  </td>
                                <td>5 </td>
                                <td>2015-01-01 at 11:53 </td>
                                <td><a onclick="setupMap('33.23478899909723', '35.57791471481323')"  href='#showMap' data-inline='true' data-mini='true' data-role='button' data-rel='popup' data-position-to="window" data-transition="pop" >Show on map</a></td>
                            </tr>

                            <tr>
                                <td> <img src="../img/couponimg.png"> </td>
                                <td>Im zero XD </td>
                                <td>2015-01-01 at 11:53 </td>
                                <td><a onclick="setupMap('33.23478899909723', '35.57791471481323')"  href='#showMap' data-inline='true' data-mini='true' data-role='button' data-rel='popup' data-position-to="window" data-transition="pop" >Show on map</a></td>
                            </tr>

                            <tr>
                                <td>  </td>
                                <td>GoodmorningDay! </td>
                                <td>2013-01-01 at 11:11 </td>
                                <td><a onclick="setupMap('33.23478899909723', '35.57791471481323')"  href='#showMap' data-inline='true' data-mini='true' data-role='button' data-rel='popup' data-position-to="window" data-transition="pop" >Show on map</a></td>
                            </tr>

                    </tbody>
                </table>

                <!-- set up map popup -->
                <div data-role="popup" id="showMap" data-overlay-theme="a" data-theme="c" class="ui-corner-all">
                    <div data-role="header" data-theme="a" class="ui-corner-top">
                        <h1>Business Location</h1>
                    </div>

                    <div data-role="content" data-theme="d" class="ui-corner-buttom ui-content">
                        <div id="heresTheMap">ccc</div>
                    </div>
                </div>
        </div>

    </body>
</html>

有什么问题?

【问题讨论】:

【参考方案1】:

您的地图 div (id="heresTheMap") 没有大小。

  <div id="heresTheMap" style="height:500px;width:500px;">ccc</div>

【讨论】:

以上是关于谷歌地图没有在我的 jQuery 移动弹出窗口上绘制? [复制]的主要内容,如果未能解决你的问题,请参考以下文章

如何使用放大弹出窗口在移动设备中显示地图?

谷歌地图信息窗口未正确显示

谷歌地图更新jquery移动问题

谷歌地图不适用于 jquery 移动框架

显示信息窗口后阻止谷歌地图移动

谷歌地图 api 长时间加载的 jQuery 移动对话框消失