繁体   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