我跟着圖書館和YouTube的指南添加標記clusterer到我的地圖,但我得到了問題。谷歌地圖API V3 - MarkerClusterer undefined
MarkerClusterer undefined
我已經在指南中定義了MarkerClusterer,但仍然出現了上述錯誤。 下面是我的代碼
<!DOCTYPE html>
<html lang="fr" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemasmicrosoft-
com:vml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="UTF-8" />
<title>Ma Page de Google Maps V3</title>
<style>
html, body, #map_canvas {
margin: 3;
padding: 3;
height: 100%;
}
</style>
<style type="text/css">
.tooltip {
background-color:#ffffff;
font-weight:bold;
border:2px #006699 solid;
width:150px}
</style>
<script src="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="http://www.google.com/jsapi"></script>
<script src="../src/data.json" type="text/javascript"></script>
<script type="text/javascript">
var script = '<script type="text/javascript" src="../src/markerclusterer';
if (document.location.search.indexOf('compiled') !== -1) {
script += '_compiled';
}
script += '.js"><' + '/script>';
document.write(script);
</script>
<script>
var trace_markers= [];
var markerCluster= null;
function Trace_Pin(Lat, Long, immat, type, site, vitesse, date)
{
var image_trace = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal3/icon61.png',
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(16, 16));
var vehlatlng = new google.maps.LatLng(Lat, Long) ;
var trace_marker = new google.maps.Marker({
position: vehlatlng,
icon: image_trace });
trace_marker.tooltip_html = '<div class="tooltip">' + 'Date : ' + date + '<br>' + 'Vitesse : ' + vitesse + ' km/h' + '<br>' + '<\/div>';
trace_markers.push(trace_marker);
markerCluster = new MarkerClusterer(map, trace_markers);
Liste_Points.push(trace_marker.getPosition());
TraceBounds.extend(trace_marker.position);
}
</script>
我哪裏做錯了?
你確定你的markerclusterer.js/markerclusterer_compiled.js文件被正確調用嗎?在嘗試引用MarkerClusterer類之前,你需要做任何事情來初始化它嗎? – duncan
另外,你從哪裏調用Trace_Pin函數?這從代碼中並不明顯 - 你是否需要調整它來等待markercluster JS文件在嘗試調用該函數之前加載? – duncan
我發現我需要從谷歌圖書館下載markerclusterer.js, [http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js 和將其上傳到服務器,然後將其添加到'',並且可以解決問題。感謝您的幫助:) – dswong