(function() {
window.onload = function() {
// Creating an object literal containing the properties we want to pass to the map
var address = [
'Atlanta, GA',
'1400 River Place Ste 300, Braselton, GA 30517',
'Gainesville, GA',
'Dawsonville, GA'
];
var options = {
// zoom: 10,
//center: new google.maps.LatLng(52.40, -3.61),
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: true
};
// Creating the map
var map = new google.maps.Map(document.getElementById('map'), options);
// Creating a LatLngBounds object
var bounds = new google.maps.LatLngBounds();
// Creating an array that will contain the addresses
var places = [];
// Creating a variable that will hold the InfoWindow object
var infowindow;
// markerclusterer
var markerCluster = new MarkerClusterer(map, markers, {
gridSize: 30,
styles: [{
url: "https://googlemaps.github.io/js-marker-clusterer/images/m1.png",
width: 53,
height: 53,
textSize: 15,
textColor: "white"
}]
});
var geocoder = new google.maps.Geocoder();
var markers = [];
// Adding a LatLng object for each city
for (var i = 0; i < address.length; i++) {
(function(i) {
geocoder.geocode({
'address': address[i]
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
places[i] = results[0].geometry.location;
// Adding the markers
var marker = new google.maps.Marker({
position: places[i]
});
markers.push(marker);
//add the marker to the markerClusterer
markerCluster.addMarker(marker);
// Creating the event listener. It now has access to the values of i and marker as they were during its creation
google.maps.event.addListener(marker, 'click', function() {
// Check to see if...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.