2013-05-21 103 views
0

我試圖實現的最後一個代碼在如何關閉信息窗口在谷歌地圖V3

https://developers.google.com/maps/articles/phpsqlinfo_v3

我想有一個取消和關閉按鈕。 所以,我修改了代碼並將其上傳到

http://adsany.com/testclose.htm (查看源)

當我在地圖上點擊,會出現一個標記,

當我點擊標記,顯示信息窗口。

當我點擊取消和關閉按鈕時,它會關閉窗口,但會出現一個新標記。

所以,我想關閉infowindow而不創建新的標記。

請建議。

謝謝。

回答

0
I hope this link will solve your Problem :- 
    http://gmaps-samples-v3.googlecode.com/svn/trunk/single-infowindow/single-infowindow.html. 


<html> 
<head> 
<title>Single Info Windows</title> 
<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"> 
    google.maps.event.addDomListener(window, 'load', function() { 
    var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 13, 
     center: new google.maps.LatLng(37.789879, -122.390442), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    var infoWindow = new google.maps.InfoWindow; 

    var onMarkerClick = function() { 
     var marker = this; 
     var latLng = marker.getPosition(); 
     infoWindow.setContent('<h3>Marker position is:</h3>' + 
      latLng.lat() + ', ' + latLng.lng()); 

     infoWindow.open(map, marker); 
    }; 
    google.maps.event.addListener(map, 'click', function() { 
     infoWindow.close(); 
    }); 

    var marker1 = new google.maps.Marker({ 
     map: map, 
     position: new google.maps.LatLng(37.789879, -122.390442) 
    }); 
    var marker2 = new google.maps.Marker({ 
     map: map, 
     position: new google.maps.LatLng(37.787814,-122.40764) 
    }); 
    var marker3 = new google.maps.Marker({ 
     map: map, 
     position: new google.maps.LatLng(37.767568,-122.391665) 
    }); 

    google.maps.event.addListener(marker1, 'click', onMarkerClick); 
    google.maps.event.addListener(marker2, 'click', onMarkerClick); 
    google.maps.event.addListener(marker3, 'click', onMarkerClick); 
    }); 
</script> 
<style type="text/css"> 
    body { 
    font-family: sans-serif; 
    } 
    #map { 
    width: 500px; 
    height: 500px; 
    } 
</style> 
</head> 
<body> 
    <h2>Demonstrates how to share a single info window on a map.</h2> 
    <ol> 
    <li>Click a marker to open a single info window containing the marker's position.</li> 
    <li>Close the opened info window by clicking anywhere on the map.</li> 
    </ol> 
    <div id="map"></div> 
</body> 
</html> 
+0

嗨,謝謝你的回覆。你能否建議我在http://adsany.com/testclose.htm的代碼中修改什麼,以便在infowindow中使用取消按鈕?謝謝。 – Arnold