-
Notifications
You must be signed in to change notification settings - Fork 1
/
markerPlugin.html
107 lines (90 loc) · 3.02 KB
/
markerPlugin.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var infowindow;
(function () {
google.maps.Map.prototype.markers = new Array();
google.maps.Map.prototype.addMarker = function(marker) {
this.markers[this.markers.length] = marker;
};
google.maps.Map.prototype.getMarkers = function() {
return this.markers
};
google.maps.Map.prototype.clearMarkers = function() {
if(infowindow) {
infowindow.close();
}
for(var i=0; i<this.markers.length; i++){
this.markers[i].set_map(null);
}
};
})();
function initialize() {
var latlng = new google.maps.LatLng(50.9406645, 6.9599115);
var myOptions = {
zoom: 12,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
//mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var a = new Array();
var t = new Object();
t.name = "test0"
t.lat = 50.9407745
t.lng = 6.9599200
a[0] = t;
var t = new Object();
t.name = "test1"
t.lat = 50.9507745
t.lng = 6.9699200
a[1] = t;
var t = new Object();
t.name = "test2"
t.lat = 50.9307745
t.lng = 6.9499200
a[2] = t;
for (var i = 0; i < a.length; i++) {
var latlng = new google.maps.LatLng(a[i].lat, a[i].lng);
map.addMarker(createMarker(a[i].name,latlng));
}
console.log(map.getMarkers());
console.log(map.getMarkers());
}
function createMarker(name, latlng) {
var marker = new google.maps.Marker({position: latlng, map: map});
google.maps.event.addListener(marker, "click", function() {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({content: name});
infowindow.open(map, marker);
});
return marker;
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:50%; height:240px;float:left;"></div>
<div id="sense" style="float:left;width:160px;height:240px;padding-left:10px;">
<script type="text/javascript"><!--
google_ad_client = "pub-9193153897929025";
/* 120x240, Erstellt 14.11.10 */
google_ad_slot = "1521852511";
google_ad_width = 120;
google_ad_height = 240;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<br style="clear: both;"/>
<button onclick="map.clearMarkers();">clear</button><br />
<h1>Google Maps Api 3.0 - Marker clearing Sample</h1>
Clear Markers
This shows how to remove all the markers from the map, using a few utility functions to achieve the equivalent of the v2's clearOverlays method.
<h1>notices</h1>
11.10.2009 - I found a <a href="http://stackoverflow.com/questions/1544739/google-maps-api-v3-how-to-remove-all-markers/1544885#1544885">extension/improvement on stackoverflow</a>
</body>
</html>