javascript Google Map API V3- MarkerClusterer 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17187215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:24:38  来源:igfitidea点击:

Google Map API V3- MarkerClusterer undefined

javascriptgoogle-maps-api-3markerclusterer

提问by dswong

I followed the library and youtube guide to add marker clusterer to my map but I got the problem.

我按照图书馆和 youtube 指南将标记聚类器添加到我的地图,但我遇到了问题。

MarkerClusterer undefined

I have defined MarkerClusterer as show in the guide, but still got the above error. below is my code

我在指南中定义了 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>

Where did I did wrong?

我哪里做错了?

回答by dswong

i found out that i need to download the markerclusterer.js from google library, http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.jsand upload it to server, then just add it to and that should solve the problem. thanks for helping :)

我发现我需要从谷歌图书馆下载 markerclusterer.js,http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js并将其上传到服务器,然后只需将其添加到即可解决问题。谢谢你的帮助:)

replace this

替换这个

<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>

with this

有了这个

<script src="http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="markerclusterer.js" type="text/javascript"></script>

回答by Shazad Maved

I just added the marker cluster plus gem to my list and it started working !

我刚刚将标记集群和 gem 添加到我的列表中,它开始工作了!

In your Gemfile, add this line:

在您的 Gemfile 中,添加以下行:

gem 'markerclustererplus-rails' You can include it by adding the following to your javascript file:

gem 'markerclustererplus-rails' 您可以通过将以下内容添加到您的 javascript 文件中来包含它:

//= require markerclusterer

//= 需要标记聚类器

Reference : https://github.com/RogerE/markerclustererplus-rails

参考:https: //github.com/RogerE/markerclustererplus-rails