看看这个 jsfiddle http://jsfiddle.net/CdRdd/2/。看看地图是如何偏离标记的?现在看看不在模态http://jsfiddle.net/CdRdd/4/中的同一张地图,它可以工作。这是怎么回事?
function initialize() {
var addresses = $('.tracking-map-marker-details');
window.map = new google.maps.Map(document.getElementById('map_canvas_trackingmap'), {
mapTypeId: google.maps.MapTypeId.HYBRID
});
var infowindow = new google.maps.InfoWindow(),
bounds = new google.maps.LatLngBounds(),
geocoder = new google.maps.Geocoder();
$(addresses).each(function() {
var address = $(this).data('address'),
letter = $(this).data('letter'),
status = $(this).data('status');
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
icon: "http://www.google.com/mapfiles/marker" + letter + ".png",
shadow: 'http://www.google.com/mapfiles/shadow50.png',
position: results[0].geometry.location,
map: map
});
bounds.extend(results[0].geometry.location);
}
});
});
var listener = google.maps.event.addListenerOnce(map, "idle", function () {
map.fitBounds(bounds);
map.setZoom(5);
$('#tracking_map_modal').modal('show').on('shown', function () {
google.maps.event.trigger(map, 'resize');
});
});
}