【发布时间】:2014-08-24 21:32:51
【问题描述】:
我正在尝试使用 js 制作标签以在网站上获得更多数据。
请查看:http://dev.ateo.dk/officelab-konferencecenter/
顶部的两个选项卡(“Billeder”和“kort”)是使用 js 制作的。
如果我进入名为“kort”的水龙头,谷歌地图将不会完全加载 - 但是如果我右键单击并使用 Firefox 选择“检查元素 (Q)”,地图会突然加载。
另外,地图没有居中。在特定位置 - 位置在左上角。
您可能会注意到标签 div 下方有一个空白方块。这与 js 选项卡中使用的代码完全相同。如果我注释掉 in js 选项卡,空白的正方形将完美运行。所以不知何故,js 选项卡与 js 谷歌地图相结合似乎不起作用。会不会是这样,如果是,如何解决?
下面我展示了将启动谷歌地图和页面上的水龙头的代码:
if($('body.single-konferencested').length > 0)
{
tabs();
}
if($('body.single-konferencested').length > 0)
{
$(document).ready(function() {
function initialize() {
var myLatlng = new google.maps.LatLng(place_lat,place_lng);
var mapOptions = {
zoom: 9,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('gmap'), mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
clickable : true
});
var pinIcon = new google.maps.MarkerImage(
"http://dev.ateo.dk/wp-content/themes/ateo/img/pin_marker.png",
null, /* size is determined at runtime */
null, /* origin is 0,0 */
null, /* anchor is bottom center of the scaled image */
new google.maps.Size(24, 40)
);
marker.setIcon(pinIcon);
var content_string = '<div id="gmap_info">'+
'<div id="siteNotice">'+
'</div>'+
'<h3 id="firstHeading" class="firstHeading">'+place_title+'</h3>'+
'<div id="bodyContent">'+
'<p>'+place_address+'<br />'+place_city_zip+'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: content_string
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
});
}
以下是显示“Kort”选项卡的 DOM 的 html:
<div class="tabContent" id="kort" style="padding: 5px 10px;">
<h2>Kort</h2>
<div id="gmap" style="width: 600px; height: 400px;"></div>
<h2>test</h2>
</div>
最好的问候 帕特里克
【问题讨论】:
标签: javascript html google-maps dom