<script type="text/javascript">
var map;
var mc; //marker clusterer
var mcOptions = { gridSize: 10, maxZoom: 8 };
var infowindow = new google.maps.InfoWindow(); //global infowindow
var geocoder = new google.maps.Geocoder(); //geocoder
var address = new Array("15.8700, 74.5000", "15.871463, 74.500777", "15.871505, 74.500884", "32.7714,-97.2915");`enter code here`
var content = new Array("Unit`enter code here`No1", "UnitNo42", "UnitNo43", "UnitNo44");
//min and max limits for multiplier, for random numbers //keep the range pretty small, so markers are kept close by
var min = .999999;
var max = 1.000001;
function createMarker(latlng, text) {
var marker = new google.maps.Marker({ position: latlng, map: map });
///get array of markers currently in cluster
var allMarkers = mc.getMarkers();
//check to see if any of the existing markers match the latlng of the new marker
if (allMarkers.length != 0) {
for (i = 0; i < allMarkers.length; i++) {
var existingMarker = allMarkers[i];
var pos = existingMarker.getPosition();
if (latlng.equals(pos)) {
text = text + " & " + content[i];
}
}
}
// WHERE TO ADD: mc.addMarker(marker); //??
google.maps.event.addListener(marker, 'click', function () {
infowindow.close();
infowindow.setContent(text);
infowindow.open(map, marker);
});
return marker;
}
function initialize() {
var options = {
zoom: 2,
center: new google.maps.LatLng(21.7679, 78.8718),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
var gmarkers = [];
for (i = 0; i < address.length; i++) {
var ptStr = address[i];
var coords = ptStr.split(",");
var latlng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1]))
gmarkers.push(createMarker(latlng, content[i]));
}
//marker cluster
mc = new MarkerClusterer(map, gmarkers, mcOptions);
for (i = 0; i < address.length; i++) {
geocodeAddress(address[i], i);
}
}
</script>
質問する
192 次