2010-12-06 22 views
1

Ich brauche den Marker zu zeigen, wenn eine Checkbox geprüft und verstecken, wenn sie nichtGoogle Maps wechselt Marker

geprüft
function initialize() { 
    //map 
    var UCM = new google.maps.LatLng(37.366572, -120.424876); 
    var myOptions = { 
     zoom : 13, 
     center : UCM, 
     mapTypeId : google.maps.MapTypeId.ROADMAP 
    }; 
    //streetview 
    var panoramaOptions = { 
     position : UCM, 
     pov : { 
      heading : 0, 
      pitch : 0, 
      zoom : 0 
     } 
    }; 
    var panorama = new google.maps.StreetViewPanorama(document 
      .getElementById("pano"), panoramaOptions); 
    var map = new google.maps.Map(document.getElementById("map_canvas"), 
      myOptions); 
    map.setStreetView(panorama); 
    //bus stops 

    var GLaps = new google.maps.LatLng(37.315284, -120.505021); 

    var infowindow = new google.maps.InfoWindow(
      { 
       content : '<br>GRANVILLE LUXURY APARTMENTS </br>' + '<br><b><FONT COLOR="#0000FF">C1 BLUE LINE</FONT></b>:(AM) 6:45, 8:05, 9:25, 10:45; (PM)12:05, 1:25, 2:45, 4:05, 5:25, 6:45, 8:05</br>' + '<br><b><FONT COLOR="cccc00">C1 GOLD LINE</FONT></b>: (AM) 7:25, 8:45, 10:05, 11:25; (PM) 12:45, 2:05, 3:25, 4:45, 6:05, 7:25, 8:45, 10:05</br>' 
      }); 
    var marker = new google.maps.Marker({ 
     position : GLaps, 
     draggable : false, 
     map : map, 
     title : 'Granville Luxury Apartments Departure Times', 
     clickable : true 
    }); 
    google.maps.event.addListener(marker, 'click', function() { 
     infowindow.open(map, marker); 
    }); 
} 
+0

Verwenden Sie bitte die Formatierungswerkzeuge! – ScottE

+0

Die Formatierung des Codes wurde korrigiert, aber ich bin mir immer noch nicht sicher, was die Frage ist. – Hamish

Antwort

0

Sie könnten einige jquery verwenden. Das Hinzufügen/Verbergen von Google-Skript unten ist nur um eine Idee zu bekommen und ich glaube nicht, dass es funktioniert.

$("#mycheckbox").click(function(){ 
    if ($(this).is(":checked")){ 
     //add marker 
     marker = new google.maps.Marker({ 
       position: location, 
       map: map 
      }); 
    } 
    else{ 
     //hide 
     marker.setMap(null); 
    } 
});