gpt4 book ai didi

javascript - 谷歌地图未填充模态弹出窗口

转载 作者:搜寻专家 更新时间:2023-10-31 22:31:36 26 4
gpt4 key购买 nike

我在用户单击 map 时使用模式弹出窗口 on this page here ,它会显示带有方向的更大 map 。

但是 map 并没有填满整个空间,我不明白为什么。当我右键单击它以 checkin chrome 检查器时,它会使 map ​​填充模态。

请原谅所有代码,但我认为最好将其全部包括在内:

       <div class="map clearfix">
<div class="bg left-contact">
<% if len(""&rsAdvert("ContactPostcode"))>0 then %>
<a href="#myModal" role="button" data-toggle="modal">
<div class="small-map" style="width:100%;height:130px;background:url(http://maps.google.com/maps/api/staticmap?center=<%=server.URLEncode(""&rsAdvert("ContactPostcode"))%>&zoom=14&size=250x250&maptype=roadmap&markers=color:ORANGE|label:A|<%=server.URLEncode(""&rsAdvert("ContactPostcode"))%>&sensor=false) center no-repeat;"></div></a>
<div class="expand"></div>
<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p><div id='map-canvas'></div></p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="/js/bootstrap/js/bootstrap.min.js"></script>
<% end if %>
</div>
</div>

<script src="http://maps.googleapis.com/maps/api/js?q=London&key=AIzaSyBaPEDyFbbnWjtvT8W3UBOM34Y7g6vK69A&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var geolocate = function(address, callback) {
$.ajax({
url: "http://maps.googleapis.com/maps/api/geocode/json",
data: {
"sensor": true,
"address": address
},
dataType: "json",
success: function(d) {
if (d.status == "ZERO_RESULTS") callback(false);
if (d.results && d.results[0] && d.results[0].geometry) {
callback({
"ne": d.results[0].geometry.bounds.northeast,
"sw": d.results[0].geometry.bounds.southwest,
"center": d.results[0].geometry.location
});
}
else callback(false);
}
});
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
geolocate("<%=server.URLEncode(""&rs("ca_postcode"))%>", function(c) {
map.setCenter(new google.maps.LatLng(c.center.lat, c.center.lng));
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

谢谢。

最佳答案

为了完整性:如果您使用 Bootstrap modal window您需要使用 shown.bs.modal 事件代替 shown 事件。

这里是代码:

  $("#modalWindowId").on("shown.bs.modal", function(e) {
google.maps.event.trigger(map, "resize");
map.setCenter(markerLatLng); // Set here center map coordinates
});

查看此处以了解更多信息: http://coderpills.wordpress.com/2014/06/02/showing-google-map-inside-a-bootstrap-modal-window/

关于javascript - 谷歌地图未填充模态弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16532411/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com