谷歌地图没有在我的jQuery手机弹出窗口上绘制?

时间:2013-12-24 14:28:18

标签: javascript jquery google-maps jquery-mobile

我有一些商家,我想在地图上绘制它们

我建立了函数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 个答案:

答案 0 :(得分:0)

你的地图div(id =“heresTheMap”)没有大小。

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