일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 함수
- .net
- 하남맛집
- 토렌트
- 국정화
- C#
- 초대장
- 박근혜 탄핵
- 신장사거리
- Lock
- 맛집
- javascript
- 재테크
- 티스토리
- 파리바게트
- 하남
- 카카오가 찾아준 헤어샵
- db
- 국정화 반대
- 트레커
- jquery
- Google Map
- 트래커
- 카카오헤어샵
- 동적쿼리
- 술안주
- MSsql
- 파리바게트 청라 SK점
- 최신트래커
- 내장함수
- Today
- Total
featur
[javascript] 구글맵 api 마커 삭제 예제 Google map API Remove Markers 본문
구글맵 api 마커 삭제 예제 Google map API Remove Markers
https://developers.google.com/maps/documentation/javascript/examples/marker-remove?hl=ko-KRChoosing
<html>
<head>
<title>Remove Markers</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
#panel {
position: absolute;
top: 10px;
left: 25%;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
text-align: center;
}
/**
* Provide the following styles for both ID and class, where ID represents an
* actual existing "panel" with JS bound to its name, and the class is just
* non-map content that may already have a different ID with JS bound to its
* name.
*/
#panel, .panel {
font-family: 'Roboto','sans-serif';
line-height: 30px;
padding-left: 10px;
}
#panel select, #panel input, .panel select, .panel input {
font-size: 15px;
}
#panel select, .panel select {
width: 100%;
}
#panel i, .panel i {
font-size: 12px;
}
</style>
</head>
<body>
<div id="panel">
<input onclick="clearMarkers();" type="button" value="Hide Markers" />
<input onclick="showMarkers();" type="button" value="Show All Markers" />
<input onclick="deleteMarkers();" type="button" value="Delete Markers" />
</div>
<div id="map">
</div>
Click on the map to add markers.
<script>
// In the following example, markers appear when the user clicks on the map.
// The markers are stored in an array.
// The user can then click an option to hide, show or delete the markers.
var map;
var markers = [];
function initMap() {
var haightAshbury = {lat: 37.769, lng: -122.446};
map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: haightAshbury,
mapTypeId: google.maps.MapTypeId.TERRAIN
});
// This event listener will call addMarker() when the map is clicked.
map.addListener('click', function(event) {
addMarker(event.latLng);
});
// Adds a marker at the center of the map.
addMarker(haightAshbury);
}
// Adds a marker to the map and push to the array.
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
markers.push(marker);
}
// Sets the map on all markers in the array.
function setMapOnAll(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() {
setMapOnAll(null);
}
// Shows any markers currently in the array.
function showMarkers() {
setMapOnAll(map);
}
// Deletes all markers in the array by removing references to them.
function deleteMarkers() {
clearMarkers();
markers = [];
}
</script>
<script async="" defer="" src="https://maps.googleapis.com/maps/api/js?signed_in=true&callback=initMap"></script>
</body>
</html>
'개발 > Javascript' 카테고리의 다른 글
[JavaScript] split , 자바스크립트 split (0) | 2015.11.04 |
---|---|
[javascript] jquery val() (0) | 2015.11.04 |
[javascript] 구글맵 API 클릭시 좌표, 검색 예제 Google Map Api Lat Lng example (0) | 2015.11.02 |
[javascript] Array.isArray 함수 (0) | 2015.11.02 |
[javascript] jQuery 체크박스 선택여부, checked처리 라디오버튼 선택과 해제 (0) | 2015.11.02 |