Google maps Google Maps v3 API MarkerCluster-需要在marker var中包装动态addMarkers
我有一个v3 Google Maps,可以很好地使用动态标记,但我正在尝试添加MarkerCluster功能,如Google文档中所述:Google maps Google Maps v3 API MarkerCluster-需要在marker var中包装动态addMarkers,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我有一个v3 Google Maps,可以很好地使用动态标记,但我正在尝试添加MarkerCluster功能,如Google文档中所述: 有人可以帮助您使用正确的语法吗?更新addMarker函数以返回标记并接受map作为参数: function addMarker(map, lat, lng, info) { var pt = new google.maps.LatLng(lat, lng); bounds.extend(pt); var marker = new google.
有人可以帮助您使用正确的语法吗?更新addMarker函数以返回标记并接受map作为参数:
function addMarker(map, lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: image,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
currentPopup = null;
});
return marker;
}
然后将标记创建部分更新为:
var mcOptions = {gridSize: 50, maxZoom: 15};
var markers = [];
<?php
do {
$name=$row_rsCity['PARKNAME'];
$lat=$row_rsCity['lat'];
$lon=$row_rsCity['lng'];
$desc=$row_rsCity['PARKADDR'];
$city=$row_rsCity['PARKCITY'];
$spaces=$row_rsCity['SPACE_CNT'];
$phone=$row_rsCity['PHONE'];
echo ("markers.push(addMarker(map, $lat, $lon,'<b>$name</b><br/>$desc<br/>$city CA<br /><br />Phone: $phone <br />Space Count: $spaces'));\n");
} while ($row_rsCity = mysql_fetch_assoc($rsCity));
?>
var mc = new MarkerClusterer(map, markers, mcOptions);
var mcOptions={gridSize:50,maxZoom:15};
var标记=[];
missing ] after element list
function addMarker(map, lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
bounds.extend(pt);
var marker = new google.maps.Marker({
position: pt,
icon: image,
map: map
});
var popup = new google.maps.InfoWindow({
content: info,
maxWidth: 300
});
google.maps.event.addListener(marker, "click", function() {
if (currentPopup != null) {
currentPopup.close();
currentPopup = null;
}
popup.open(map, marker);
currentPopup = popup;
});
google.maps.event.addListener(popup, "closeclick", function() {
currentPopup = null;
});
return marker;
}
var mcOptions = {gridSize: 50, maxZoom: 15};
var markers = [];
<?php
do {
$name=$row_rsCity['PARKNAME'];
$lat=$row_rsCity['lat'];
$lon=$row_rsCity['lng'];
$desc=$row_rsCity['PARKADDR'];
$city=$row_rsCity['PARKCITY'];
$spaces=$row_rsCity['SPACE_CNT'];
$phone=$row_rsCity['PHONE'];
echo ("markers.push(addMarker(map, $lat, $lon,'<b>$name</b><br/>$desc<br/>$city CA<br /><br />Phone: $phone <br />Space Count: $spaces'));\n");
} while ($row_rsCity = mysql_fetch_assoc($rsCity));
?>
var mc = new MarkerClusterer(map, markers, mcOptions);