[google maps API] 關閉前一個 infowindow
- var currentInfoWindow = ''; //Global variable
- google.maps.event.addListener(marker, 'click', function()
- {
- if(currentInfoWindow != '')
- {
- currentInfoWindow.close();
- currentInfoWindow = '';
- }
- var infoWindow = new google.maps.InfoWindow({content: 'COntent'});
- infowindow.open(map, marker);
- currentInfoWindow = infowindow;
- });
- // Initialize infowindow
- var infowindow = new google.maps.InfoWindow({content: ''});
- function add_marker(point, name, content)
- {
- var marker = new google.maps.Marker({
- map: map,
- position: point,
- dragable: false,
- clickable: true,
- name: name
- });
- marker.content = content;
- google.maps.event.addListener(marker, 'click', function()
- {
- infowindow.content = marker.content;
- infowindow.open(map, marker);
- });
- return marker;
- };
- function addPostCode(zip, html)
- {
- geocoder.geocode( { 'address': zip}, function(results, status)
- {
- if (status == google.maps.GeocoderStatus.OK)
- {
- map.setCenter(results[0].geometry.location);
- var marker = add_marker(results[0].geometry.location, zip, html)
- });
- });
很常會使用到的。
出處
留言