【发布时间】:2013-12-26 21:17:45
【问题描述】:
我正在尝试将谷歌地图方向加载为 Bootstrap 轮播中的一张幻灯片。
不太清楚为什么这张地图会以现在的方式加载。如果我删除轮播中的第一项,则地图加载正常。只有当地图是第二个项目时,它才会奇怪地加载。
任何想法如何解决这个问题并正确加载地图?
HTML:
<div id="carousel-1" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#carousel-1" data-slide-to="0" class="active"></li>
<li data-target="#carousel-1" data-slide-to="1" ></li>
</ol>
<div class="carousel-inner">
<div class="item active" style="height: 450px; width: 100%;">
ABC
</div>
<div class="item">
<div id="map-canvas" style="height: 450px; width: 100%;">
</div>
</div>
</div>
<!-- Carousel Controls -->
<a class="left carousel-control" href="#carousel-1" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-1" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
Javascript
$(document).ready(function(){
var $canvas = $('#map-canvas');
var dstLatLng = new google.maps.LatLng(37.403867, -121.975405);
var orgLatLng = new google.maps.LatLng(37.4321365, -122.0988141);
var directionsRenderer = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
var request = {
origin: orgLatLng,
destination: dstLatLng,
travelMode: google.maps.TravelMode.DRIVING
};
var mapOptions = {
zoom: 8,
center: dstLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($canvas[0], mapOptions);
directionsRenderer.setMap(map);
directionsService.route(request, function(result, status) {
if (status === google.maps.DirectionsStatus.OK) {
return directionsRenderer.setDirections(result);
}
});
$('.carousel').carousel();
})
【问题讨论】:
标签: google-maps-api-3 twitter-bootstrap-3