これはコード全体です:
function initialize(){
var deutschland = new google.maps.LatLng(51,9);
var mapOptions = { zoom: 6,
center: deutschland,
streetViewControl: true,
scaleControl: true,
mapTypeControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById("map-container"),mapOptions);
var beaches = [
['Bondi Beach', 51, 9, 1],
['Coogee Beach', 52, 9, 1],
['Cronulla Beach', 51, 8, 2],
['Manly Beach',51.5, 9, 2],
['Maroubra Beach',52.5, 10, 2]
];
var markers = [];
var i, newMarker;
for (i = 0; i < beaches.length; i++) {
newMarker = new google.maps.Marker({
position: new google.maps.LatLng(beaches[i][1], beaches[i][2]),
map: map,
title: beaches[i][0]
});
newMarker.category = beaches[i][3];
newMarker.setVisible(true);
markers.push(newMarker);
}
}
function displayMarkers(category) {
var i;
for (i = 0; i < markers.length; i++) {
if (markers[i].category == category) {
if (markers[i].getVisible()) {
markers[i].setVisible(false); }
else { markers[i].setVisible(true); } } }
}
と:
<input type="button" value="Show Group 1" onclick="displayMarkers(1);"/>
<input type="button" value="Show Group 2" onclick="displayMarkers(2);"/>