1

我想通過點擊鏈接HTML來隱藏標記。我寫了一些代碼,但它不起作用。有人能告訴我什麼是錯的嗎?隱藏標記Google Maps API v3,點擊一下

var markers = []; 

var cuicui= [ 
    [45.710743, 4.934347],  
    [45.691894, 4.923193], 
    [45.713855, 4.928156], 
    [45.710238, 4.965208], 
    [45.713550, 4.930187], 
    [45.712871, 4.928613], 
    [45.698959, 4.918937], 
    [45.709566, 4.923370], 
    [45.715945, 4.931199], 
    [45.715824, 4.912740] 
]; 

for (i = 0; i < cuicui.length; i++) { 
    var position = new google.maps.LatLng(cuicui[i][0], cuicui[i][1]), 
     marker = new google.maps.Marker({ 
     position: position, 
     map: map 
    }); 

    markers.push(marker); 

    google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     })(marker, i)); 

    marker.setVisible(false); 

    google.maps.event.addDomListener(document.getElementById('cuicui'), 'click', function() { 
     if (marker.setVisible(false)) { 
      marker.setVisible(true); 
     } else { 
      marker.setVisible(false); 
     } 
    }); 
} 

而在我的HTML我有:

<a style="cursor : pointer;" id="cuicui">Ici</a> 

+0

請參閱文檔在這個例子中:https://developers.google.com/maps/documentation/javascript/ examples/marker-remove – bcdan

回答

1

而是調用setVisible的();(對不起,我的英語。)使用setMap();

marker.setMap(map); 

使其出現和

marker.setMap(null); 

,使其隱形

+0

謝謝你的回答,但它仍然不起作用... 但是沒有錯誤報告 – Luna