Skip to content

Instantly share code, notes, and snippets.

@agriboz
Last active December 13, 2015 23:59
Show Gist options
  • Save agriboz/749e6caa1e4c1e9607ce to your computer and use it in GitHub Desktop.
Save agriboz/749e6caa1e4c1e9607ce to your computer and use it in GitHub Desktop.
Placing multiple markers on a google map
var markers = [
['Bondi Beach', -33.890542, 151.274856],
['Coogee Beach', -33.923036, 151.259052],
['Cronulla Beach', -34.028249, 151.157507],
['Manly Beach', -33.80010128657071, 151.28747820854187],
['Maroubra Beach', -33.950198, 151.259302]
];
function initializeMaps() {
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
var infowindow = new google.maps.InfoWindow();
var marker, i;
var bounds = new google.maps.LatLngBounds();
for (i = 0; i < markers.length; i++) {
var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(pos);
marker = new google.maps.Marker({
position: pos,
map: map,
//icon: 'http://google-maps-icons.googlecode.com/files/factory.png' change marker
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i][0]);
infowindow.open(map, marker);
}
}
})(marker, i));
map.fitBounds(bounds);
}
document.body.onload = function () {
initializeMaps();
}
//http://www.dreamdealer.nl/tutorials/placing_multiple_markers_on_a_google_map.html
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment