Casey P Thomasのソリューションを使用して、1つの場所で複数のマーカーを処理します。
例: http: //maps.caseypthomas.org/ex/MarkerClustererPlus/exCoincidentMarkers_SharedInfowindow_wGeocoding.html
それはうまく機能し、コンテンツを単一の情報ウィンドウに結合しますが、マップを壊しているAPIにはジオコーディングの制限があるようです。渡す座標のリストがあるので、住所をジオコーディングする必要はありません。
だから私の質問は、JSからジオコーディング機能をバイパスしてそのように地図を作成するにはどうすればよいですか?
ありがとう
私が使用しているコード:
var map;
//marker clusterer
var mc;
var mcOptions = {gridSize: 20, maxZoom: 17};
//global infowindow
var infowindow = new google.maps.InfoWindow();
//geocoder
var geocoder = new google.maps.Geocoder();
//Content and Geos
var address = new Array(<?php echo $tweetgeos;?>);
var content = new Array(<?php echo $tweets;?>);
function createMarker(latlng,text) {
var marker = new google.maps.Marker({
position: latlng
});
///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];
}
}
}
google.maps.event.addListener(marker, 'click', function() {
infowindow.close();
infowindow.setContent(text);
infowindow.open(map,marker);
});
return marker;
}
function geocodeAddress(address,i) {
geocoder.geocode( {'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = createMarker(results[0].geometry.location,content[i]);
mc.addMarker(marker);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
function initialize(){
var options = {
zoom: 5,
center: new google.maps.LatLng(51.50733,-0.12768),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
//marker cluster
mc = new MarkerClusterer(map, [], mcOptions);
for (i=0; i<address.length; i++) {
geocodeAddress(address[i],i);
}
}
google.maps.event.addDomListener(window, 'load', initialize);