當(dāng)用戶選擇一個(gè)復(fù)選框并單擊“在地圖上顯示”時(shí),我試圖顯示某些標(biāo)記。選擇“高迪之旅”時(shí)應(yīng)顯示 2 個(gè)標(biāo)記,選擇“哥特式之旅”時(shí)應(yīng)顯示兩個(gè)不同的標(biāo)記。但是,它不會(huì)過濾 createMarkers() 函數(shù)中的結(jié)果,而是在單擊按鈕時(shí)顯示所有標(biāo)記。我不明白為什么它沒有過濾結(jié)果,我沒有收到任何錯(cuò)誤。<section> <div class="container"> <h2>Choose your tour:</h2> <div class="container" id="selectTour"> <div class="form-check-inline"> <label class="form-check-label"> <input type="checkbox" class="form-check-input" id="one">Gaudi Tour </label> </div> <div class="form-check-inline"> <label class="form-check-label"> <input type="checkbox" class="form-check-input" id="two">Gothic Tour </label> </div> </div> <div class="container"> <button onclick="updateMarkers();">Show on Map</button> </div> <!--The Map--> <div class="container"> <div id="map"></div> </div> </div> </section>var map;var markers = [];//---------------------Data of Locations-----------------let locations = [{ name: 'one', tour: 'gaudi', coords: { lat: 41.403706, lng: 2.173504 }, content: 'google', }, { name: 'one', tour: 'gaudi', coords: { lat: 41.4145, lng: 2.1527 }, content: 'maps', }, { name: 'two', tour: 'gothic', coords: { lat: 41.3839, lng: 2.1821 }, content: 'are' }, { name: 'two', tour: 'gothic', coords: { lat: 41.3840, lng: 2.1762 }, content: 'annoying' }];//---------------------Initializing Map-----------------function initMap() { var mapOptions = { center: new google.maps.LatLng(41.3851, 2.1734), zoom: 12 }; map = new google.maps.Map(document.getElementById("map"), mapOptions);}任何建議都會(huì)有很大幫助。
使用復(fù)選框過濾 Google 地圖標(biāo)記
收到一只叮咚
2021-06-09 06:09:12