【发布时间】:2014-01-18 15:05:58
【问题描述】:
我的(减少的)代码如下。在我单击或稍微移动地图之前,我的标记不会显示...有什么办法可以解决这个问题,让它们立即显示?
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>TSF - Labour Plan </title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
function initialize() {
var centerlatlng = new google.maps.LatLng(53.644638, -2.526855);
var myOptions = {
zoom: 6,
center: centerlatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var latlng = new google.maps.LatLng(51.752927, -0.470095);
var img = "https://dl.dropboxusercontent.com/u/55888592/tsf-logo.gif";
var info = "<img style = 'float: left' src='http://www.tsf.uk.com/wp-content/themes/default/images/tsf-logo.gif'><div style = 'float: right; width: 200px'><p><b>Job Number:</b> </p><p><b>Client:</b> ASDA</p><p><b>Location:</b> HEMEL HEMPSTEAD</p><p><b>Postcode:</b> HP2 4AA</p><p><b>Start Time:</b> 22:0</p><p><b>No of Men:</b> 10.0</p><p><b>Allocated Labour:</b> AB: 5.0, WK: 5.0, : , : , : , : </p><p><b>Job Information: </b>PICK UP TOOLS</div>";
var infowindow = new google.maps.InfoWindow({
});
var marker = new google.maps.Marker({
icon: img,
position: latlng,
map: map,
content: info
});
marker.setMap(map);
google.maps.event.addListener(marker, "click", function(content) {
infowindow.setContent(this.content);
infowindow.open(map,this);
});
}
google.maps.event.addDomListener(window, "load", initialize);
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map_canvas" style="width: 100%; height: 100%;"></div>
</body>
</html>
【问题讨论】:
-
您调用了两次
initialize,一次是DomListener,一次是body onload。我会删除body onload电话。看看是否有帮助。我还会将您的 javascript 从头部移到身体中。在本地,我没有任何问题。 -
我试过了,但没有运气。我刚刚在资源管理器中检查了它,它工作正常,所以这个问题似乎与 chrome 有关?我可以在网上找到的唯一类似问题是:groups.google.com/forum/#!topic/google-maps-api/jLsVUoF9-Zk
-
我在 Mac 上的 Chrome 中没有任何问题。也许是因为缺少 DOCTYPE?在文件顶部添加
<!DOCTYPE HTML>。 -
你是如何简化代码的?你看到这个版本的问题了吗?您使用的是 MarkerClusterer 还是 MarkerManager(在未缩减的版本中)?
-
我的完整代码只是有更多标记,是的,我遇到了这个版本的问题。不,我没有使用 markerclusterer 或 markermanager。
标签: javascript google-maps google-maps-api-3 google-maps-markers