我有一個谷歌地圖(使用API V3),我需要爲它設置標記聚類。基本上,標記位置通過JSON加載,並返回問題(1或2),緯度和經度。谷歌地圖 - 聚類標記
我試圖設置羣集,但是即使JSON調用實際返回點,地圖上也沒有顯示任何內容。這裏是我想出了:
var map;
function myMap(){
var latlng = new google.maps.LatLng(35.94, 14.37);
var mapOptions = {
zoom: 10,
center: latlng,
panControl: false,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false,
zoomControl: true};
map = new google.maps.Map(document.getElementById("map"), mapOptions);
loadMarkers();
}
function loadMarkers() {
var mcOptions = {gridSize: 50, maxZoom: 15};
var issueSevereMarkers = [];
var issueSlightMarkers = [];
markerIssueHigh = new google.maps.MarkerImage("img/icn_issue_high.png",
new google.maps.Size(10.0, 10.0),
new google.maps.Point(0, 0),
new google.maps.Point(5.0, 5.0)
);
markerIssueMedium = new google.maps.MarkerImage("img/icn_issue_medium.png",
new google.maps.Size(10.0, 10.0),
new google.maps.Point(0, 0),
new google.maps.Point(5.0, 5.0)
);
var issuePoints = $.ajax({
type: 'GET',
url: 'http://www.mydomain.com/php/markers.php?&jsoncallback=?',
dataType: 'JSONp',
timeout: 5000,
success: function(data) {
$.each(data, function(i,item){
if (item.Issue == 1) {
// If severely congested
var latLng = new google.maps.LatLng(item.Latitude, item.Longitude);
var issueSevereMarker = new google.maps.Marker({'position': latLng});
issueSevereMarkers.push(issueSevereMarker);
} else if (item.Issue == 2) {
// If slightly congested
var latLng = new google.maps.LatLng(item.Latitude, item.Longitude);
var issueSlightMarker = new google.maps.Marker({'position': latLng});
issueSlightMarkers.push(issueSlightMarker);
}
});
var markerClusterSevere = new MarkerClusterer(map, issueSevereMarkers);
var issueSlightMarkerCluster = new MarkerClusterer(map, issueSlightMarkers);
},
error: function(data) {
}
});
}
基本上我在做什麼是JSON得到的結果,如果問題是1型的,我加一個引腳到issueSevereMarkers陣列,否則我將它添加到issueSlightMarkers數組。這應該使用標記的點加載數組。我不確定我在那裏做錯了什麼。
另外我遇到的另一個問題是clusterer基本上返回一個自定義圖標,我想當標記被分組時。當我放大並看到各個標記時,如何設置標記以使用markerIssueHigh和markerIssueMedium圖像?
我現在用的是Clustere爲V3(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html)