Hi,
I have a map that shows up to 30,000 markers, all loaded from the store database table upon user query. but normaly it shows upto 1000 markers.
Problem:
Some latitude and longitude in database are duplicate, which are needed. when these are plotted on the map they overlapping each other. Resulting the user cant see all the markers, these need to be clicked by the user to show more info and etc.
Question:
Is is possible to show on the map, those hidden markers?
Thanks.
What I have tried:
var map;
var mc;
var mcOptions = {gridSize: 20, maxZoom: 17};
var infowindow = new google.maps.InfoWindow();
var geocoder = new google.maps.Geocoder();
var address = new Array("1000 Market St, Philadelphia, PA","1000 Market St, Philadelphia, PA","1002 Market St, Philadelphia, PA","1004 Market St, Philadelphia, PA");
var content = new Array("1","2","3","4");
var min = .999999;
var max = 1.000001;
function createMarker(latlng,text) {
var allMarkers = mc.getMarkers();
var finalLatLng = latlng;
if (allMarkers.length != 0) {
for (i=0; i < allMarkers.length; i++) {
var existingMarker = allMarkers[i];
var pos = existingMarker.getPosition();
if (latlng.equals(pos)) {
var newLat = latlng.lat() * (Math.random() * (max - min) + min);
var newLng = latlng.lng() * (Math.random() * (max - min) + min);
finalLatLng = new google.maps.LatLng(newLat,newLng);
}
}
}
var marker = new google.maps.Marker({
position: finalLatLng
});
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: 13,
center: new google.maps.LatLng(39.96225,-75.13222),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), options);
mc = new MarkerClusterer(map, [], mcOptions);
for (i=0; i<address.length;>
geocodeAddress(address[i],i);
}
}