簡體   English   中英

引導模式下的谷歌地圖無法正常工作

[英]google map in bootstrap modal not working properly

我試圖在一段時間內以引導模式顯示google map,我在這里搜索了討論該主題的所有答案,但到目前為止對我來說沒有任何作用。 我知道我必須在模式打開后使用調整大小觸發器,的確確實使用了它,但是似乎沒有任何工作對我來說非常令人沮喪。 請幫助!

這是我使用的代碼:

<script type="text/javascript"
    src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
myLatlng = new google.maps.LatLng(32.0260053,34.8987034);
function initialize() {
    var myOptions = {
        zoom: 14,
        center: myLatlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById('map-canvas'),
                              myOptions);        
    $('.myMapModal').on('show.bs.modal', function() {

        google.maps.event.trigger(map, 'resize');
        return map.setCenter(myLatlng);
    });
}
google.maps.event.addDomListener(window, 'load', initialize);

HTML:

<div class="modal myMapModal fade" id="myMapModal" >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">#f16#</h4>
                </div>
                <div class="modal-body map-modal">
                    <div class="container">
                        <div class="row">
                            <div id="map-canvas" style="width: 500px; height: 480px;"></div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">סגירה</button>
                </div>
            </div>
        </div>
    </div>  

我得到以下內容,它可能會幫助其他人。

BootstrapDialog.show({
            title: 'Point on Map',
            message: ''<div id="selction_map"></div>'',
            onshown: function(dialogRef){
                initMap();
            }
        });

https://nakupanda.github.io/bootstrap3-dialog/

看看這個: JSFiddle可以為您服務

$("#myMapModal").ready(function() {
    $(window).resize(function() {
        google.maps.event.trigger(map, 'resize');
    });
    $('#myMapModal').modal('show');
    google.maps.event.trigger(map, 'resize');
    return map.setCenter(myLatlng);
});

暫無
暫無

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

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