我正在使用谷歌地图嵌入式api来显示两点之间的方向。
<p><iframe width='600' height='450' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyAb9sz-Ih7YtVpdvoT5mLqgkJBx99yR8bc&origin=Anand,+Gujarat,+India&destination=Ahmedabad,+Gujarat,+India&mode=driving'></iframe></p>
每次在html文件中都可以正常工作。
但是当我把它放在bootstrap3模态体中时,它只工作一次,现在它没有显示正确的地图,而是显示整个世界地图。
我必须缩放才能查看实际路线。
下面是相同的bootstrap代码。
<html>
<!--<![endif]-->
<head>
<link rel="stylesheet" href="../css/bootstrap.min.css" />
<link rel="stylesheet" href="../css/bootstrap-theme.min.css" />
</head>
<body>
<!-- Button trigger modal -->
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-cancel"></i></a>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p><iframe width='600' height='450' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyAb9sz-Ih7YtVpdvoT5mLqgkJBx99yR8bc&origin=Anand,+Gujarat,+India&destination=Ahmedabad,+Gujarat,+India&mode=driving'></iframe></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- javascript
================================================== -->
<!-- These are all the javascript files -->
<script src="../js/jquery-1.10.2.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/color-picker.js"></script>
</body>
</html>
无法弄清楚可能是什么问题?
答案 0 :(得分:3)
代码工作正常..尝试在浏览器中删除缓存并重试..
<!-- Button trigger modal -->
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">Launch demo modal</a>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<a type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-cancel"></i></a>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p><iframe width='600' height='450' frameborder='0' style='border:0' src='https://www.google.com/maps/embed/v1/directions?key=AIzaSyAb9sz-Ih7YtVpdvoT5mLqgkJBx99yR8bc&origin=Anand,+Gujarat,+India&destination=Ahmedabad,+Gujarat,+India&mode=driving'></iframe></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
答案 1 :(得分:0)
我一直有同样的问题。
在网上搜了几个小时(可能是几天)后,我终于为我的地图显示器写了一个自定义模态对话框:
HTML
<div id="viewmap" class="modalDialog">
<div>
<a href="#calendar" runat="server" title="Close" class="close">X</a>
<h4>Map to <%: evnt.VenueName %></h4>
<iframe
width="100%"
height="450"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=API_KEY&q=ADDRESS&zoom=15">
</iframe>
</div>
</div>
CSS
.modalDialog,
.modalDialog > iframe{
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,.8);
z-index: 99999;
opacity: 0;
-o-transition: opacity 400ms ease-in;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: all;
}
.modalDialog > div {
padding-top: 10px;
width: 700px;
position: relative;
margin: 2.5% auto;
padding: 5px 20px 13px 20px;
border-radius: 10px;
background: #333;
}
这个模态对话框和bootstrap的区别在于CSS只是将不透明度设置为0(完全不可见),而不是完全隐藏div。当它成为目标时,它会将不透明度设置为1.
如果您注意到,我的封闭式锚标签链接到:&#34; #calendar&#34; ...如果您只是链接到&#34;#&#34;它会带你回到页面顶部。
希望有所帮助。
答案 2 :(得分:0)
您可以在加载后将iframe注入模式,然后通过CSS应用样式。
$('#myModal').on('shown.bs.modal', function () {
$('#myModal .modal-body').html('<iframe src="https://www.google.com/maps/embed/v1/directions?key=AIzaSyAb9sz-Ih7YtVpdvoT5mLqgkJBx99yR8bc&origin=Anand,+Gujarat,+India&destination=Ahmedabad,+Gujarat,+India&mode=driving" frameborder="0" style="border:0"></iframe>');
});
在我的情况下,我需要框架为100%高度&amp;宽度和这很好地工作:)