codice:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

<script type="text/javascript">

function initialize() {
        var latlng = new google.maps.LatLng(52.474, -1.868);

        var myOptions = {
            zoom: 6,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById("map"), myOptions);
        var image = "http://maps.google.com/mapfiles/ms/icons/green-dot.png";
        var image2 = "http://maps.google.com/mapfiles/ms/icons/red-dot.png";
        

        var hotels = [
            ['ibis Birmingham Airport', 52.452656, -1.730548, 4],
            ['ETAP Birmingham Airport', 50.452527, -1.031644, 3],
            ['ibis Birmingham City Centre', 51.475162, -2.897208, 2]
        ];
        var bars = [
            ['ibis Birmingham Airport', 51.452656, -1.730548, 4],
            ['ETAP Birmingham Airport', 53.452527, -1.531644, 3],
            ['ibis Birmingham City Centre', 52.475162, -1.297208, 2]
        ];
        var markersArray = [];
        

       for (var i = 0; i < hotels.length; i++) {
        var hotel = hotels [i]
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng (hotel[1], hotel[2]),
            map: map,
            icon: image,
            title: hotel[0],
            zIndex: hotel[3]
        });
        markersArray.push(marker);
    } 
    
        for (var i = 0; i < bars.length; i++) {
        var bar = bars [i]
                
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng (bar[1], bar[2]),
            map: map,
            icon: image2,
            title: bar[0],
            zIndex: bar[3]            
        });
        markersArray.push(marker);
    }
    
    google.maps.Map.prototype.clearMarkers = function() {
    for(var i=0; i < markersArray.length; i++){
       markersArray[i].setMap(null);
    }
    markersArray = new Array();
};

//markersArray.push(marker);
google.maps.event.addListener(marker,"click",function(){});

    
   }

window.onload = initialize;


</script>
</head>

<body>
<input type="button" onclick="google.maps.Map.prototype.clearMarkers()" value="settare null">

        <div id="map" style="width:500px; height:500px"></div>
  

</body>
</html>



Ecco il codice corretto, lascio a te capire l'errore