1
Google지도를 만들면 기본적으로 몇 개의 표식이 표시됩니다. 사용자가 특정 위치를 입력하면 해당 위치의 마커 만 남아 있어야하고 나머지 작업은 사라져야합니다. 다음과 같이 마커와지도가 작동하는 동안, 필터 기능을하지 working.My JS 코드는 다음과 같습니다knockout- Google지도 표식 필터
function inintMap()
{
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId : 'roadmap'
};
map = new google.maps.Map(document.getElementById('map'),mapOptions);
map.setTilt(45);
var locations = [
['London Eye, London', 51.503454,-0.119562],
['Palace of Westminster, London', 51.499633,-0.124755]
];
for (i=0; i < locations.length; i++)
{ var position = new google.maps.LatLng(locations [i][1],locations [i][2]);
bounds.extend (position);
marker = new google.maps.Marker({
position : position,
map : map,
title : locations [i][0]
});
map.fitBounds(bounds);
}
var vm = {
locations: ko.observableArray(locations)
};
vm.query = ko.observable('')
vm.search = function(value){
vm.locations.removeAll()
for(var x in locations) {
if(locations[x].name.toLowerCase().indexOf(value.toLowerCase()) >= 0) {
viewModel.locations.push(locations[x]);
}
}
}
vm.query.subscribe(vm.search);
ko.applyBindings(vm);
}
http://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea –
콘솔에 오류가 있습니까? 어떤 방법으로 작동하지 않습니까? –