마커 그룹을 보여줄 수있는 Google지도를 만드는 중입니다. 한 지역의 모든 레스토랑이나 공원을 말하십시오. 현재 나는 일련의 레스토랑과 일련의 공원을 만들 수있었습니다. 각각의 공원에는 자체 마커 색상이 있습니다. 지도 아래의 텍스트를 클릭하여 모든 마커를 숨기거나 표시 할 수도 있습니다. 하지만 이제 마커를 범주로 분리하여 확인란을 기반으로 숨기거나 표시 할 수 있습니다. 아래의 코드는,하지만 여기에 내가 할 싶은 일이 있습니다 :Google지도 마커를 카테고리 또는 그룹별로 숨기거나 표시합니다.
- 지도는 내가 자신의 범주로 마커를 분리 숨기고 각을 표시 할 수 있습니다
- 기본적으로 어떤 마커 비어 있어야합니다 카테고리
- 여러 종류가 한 번 여기에
에 표시 할 수있는 것은 내 코드입니다
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Maps Multiple Markers</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script></script>
</head>
<body>
<div id="map" style="width: 100%; height: 650px;"></div>
<p><a onClick="clearMarkers();">Clear Markers</a></p>
<p><a onClick="showRestaurants();">Show Markers</a></p>
<script type="text/javascript">
//Restaurants Markers
var restaurants = [
['Melt Bar and Grill', 41.485345, -81.799047],
['Sloane Pub', 41.486182, -81.824178],
['Spitfire Salon', 41.479670, -81.768430],
['Mahall\'s', 41.476989, -81.781094],
['Szechwan Garden', 41.485615, -81.787890]
];
//Parks Markers
var parks = [
['Lakewood Park', 41.494457, -81.797605],
['Madison Park', 41.476969, -81.781929],
['Tuland Park', 41.464052, -81.788041]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 14,
center: new google.maps.LatLng(41.485345, -81.799047),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var markers = new Array();
//Create and Place Restaurant Markers
for (i = 0; i < restaurants.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(restaurants[i][1], restaurants[i][2]),
map: map,
icon: 'images/markers/red_Marker.png'
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(restaurants[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
//Create and Place Parks Markers
for (i = 0; i < parks.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(parks[i][1], parks[i][2]),
map: map,
icon: 'images/markers/blue_Marker.png'
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(parks[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
// Sets the map on all markers in the array.
function setAllMap(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setAllMap(null);
}
// Shows any markers currently in the array.
function showRestaurants() {
setAllMap(map);
}
</script>
</body>
</html>
"요구 사항"목록에 무엇이 효과가 있습니까? 작동하지 않는 것은 무엇입니까? [게시 된 코드의 바이올린] (http://jsfiddle.net/shh8ecxd/) – geocodezip
3 번 순간에 작업 중입니다. 공원과 식당을 모두 보여줄 수 있습니다. 나는 그들이 트리거되기 전까지는 기본 설정에 있지 않기를 원합니다.하지만 개별적으로 숨기고 표시하는 방법을 알지 못합니다. 지금은 나에게 무의미한 것입니다. – briazzi