Javascript 如何使用谷歌地图';Marker Clusterer Plus';

Javascript 如何使用谷歌地图';Marker Clusterer Plus';,javascript,google-maps-api-3,google-geocoder,Javascript,Google Maps Api 3,Google Geocoder,我用这个例子: var位置=[ ['Location 1 Name'、'New York,NY'、'Location 1 URL'], [“位置2名称”,“新泽西州纽瓦克”,“位置2 URL'], ['Location 3 Name','Philadelphia,PA','Location 3 URL'] ]; var地理编码器; var映射; var bounds=new google.maps.LatLngBounds(); 函数初始化(){ map=新建google.maps.map(

我用这个例子:

var位置=[
['Location 1 Name'、'New York,NY'、'Location 1 URL'],
[“位置2名称”,“新泽西州纽瓦克”,“位置2 URL'],
['Location 3 Name','Philadelphia,PA','Location 3 URL']
];
var地理编码器;
var映射;
var bounds=new google.maps.LatLngBounds();
函数初始化(){
map=新建google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
geocoder=新的google.maps.geocoder();
对于(i=0;i

”; iw=新建google.maps.InfoWindow({ 内容:html, 最大宽度:350 }); iw.打开(地图、标记); }); } 函数createMarker(结果){ var marker=new google.maps.marker({ 图标:'http://maps.google.com/mapfiles/ms/icons/blue.png', 地图:地图, 位置:结果[0]。geometry.location, 标题:标题,, 动画:google.maps.animation.DROP, 地址:地址:, url:url }) extend(marker.getPosition()); 映射边界(bounds); 信息窗口(标记、地图、标题、地址、url); 返回标记; }
html,主体,#映射#画布{
高度:500px;
宽度:500px;
边际:0px;
填充:0px
}

相关问题:

一个选项是在全局范围内创建MarkerClusterer,然后在创建标记时将其添加到geocoder回调函数中的clusterer

在初始化函数中:

clusterer = new MarkerClusterer(map, [], {
  imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
然后在geocoder回调中:

clusterer.addMarker(marker);

代码片段:

var位置=[
['Location 1 Name'、'New York,NY'、'Location 1 URL'],
[“位置2名称”,“新泽西州纽瓦克”,“位置2 URL'],
['Location 3 Name','Philadelphia,PA','Location 3 URL'],
[“位置4名称”,“新泽西州特伦顿”,“位置4 URL'],
['Location 5 Name','Philadelphia,PA','Location 5 URL'],
['Location 6 Name','Jersey City,NJ','Location 6 URL']
];
var地理编码器;
var映射;
var bounds=new google.maps.LatLngBounds();
var聚类器;
函数初始化(){
map=新建google.maps.map(
document.getElementById(“地图画布”){
中心:新google.maps.LatLng(37.4419,-122.1419),
缩放:13,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
聚类器=新的标记聚类器(映射,[]{
imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
geocoder=新的google.maps.geocoder();
对于(i=0;i

”; iw=新建google.maps.InfoWindow({ 内容:html, 最大宽度:350 }); iw.打开(地图、标记); }); }
html,
身体,
#地图画布{
高度:500px;
宽度:500px;
边际:0px;
填充:0px
}