0
大師,問候語:如何自動關閉infoWindow?
我有一個關於JavaScript的問題。我寫了一個JavaScript補丁,在Google地圖上顯示多個標記。這些標記的地理編碼和相關信息從數據庫中檢索,並在APEX中使用JSON傳遞數據。問題是:如果用戶點擊另一個標記,我想關閉標記的infowindow。我試圖設置只有一個infowindow全局變量,它確實實現了我的目的,當我點擊另一個標記時,infowindow會自動關閉,但是每個標記都會在infowindow中獲得相同的內容。有人幫我解決這個問題嗎?您的幫助將不勝感激。
這裏是我的代碼
<img src="#WORKSPACE_IMAGES#1938.JPG"\><script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
var infoWindow;
function initialize() {
//var test_geo=$v('P3016_H_RESIDENT_GEOCODING');
//alert(test_geo);
var myOptions = { zoom: 18, mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var markerBounds = new google.maps.LatLngBounds();
var point=new google.maps.LatLng(&P3016_H_RESIDENT_GEOCODING.);
markerBounds.extend(point);
map.fitBounds(markerBounds);
var listener = google.maps.event.addListener(map, "idle", function() {
map.setZoom(map.getZoom()-8);
google.maps.event.removeListener(listener);
});
var json_obj = $v('P3016_H_JSON');
var obj = jQuery.parseJSON(json_obj);
var markers= new Array();
var current_parameter;
var my_URL;
var test_prefix = $v('P3016_H_APEX_PREFIX');
for (var u = 0; u < obj.Offenders.length; u++){
var user = obj.Offenders[u];
markers[u] = new google.maps.Marker({ position: new google.maps.LatLng(obj.Offenders[u].LA,obj.Offenders[u].LO), map: map });
current_parameter ="&APP_ID.:216:&SESSION.::NO::O:"+user.cs;
my_URL=my_URL=test_prefix+encodeURIComponent(current_parameter);
my_URL='<a href='+my_URL+'>'+user.Name+'</a>'+'\n'+user.Addr;
addInfoWindow(markers[u], my_URL);
}
function addInfoWindow(marker, message) {
var info = message;
infoWindow = new google.maps.InfoWindow({
content: message
});
google.maps.event.addListener(marker, 'click', function() {
//if (infoWindow.getMap()){
// infowWindow.close();
//}
infoWindow.open(map, marker);
});
}
var radius_in_miles=$v('P3016_H_RADIUS_M');
var circle = {
strokeColor: "#ff0000",
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: "#ff0000",
fillOpacity: 0.20,
map: map,
center: point,
radius: 1609.3*radius_in_miles };
var drawCirle = new google.maps.Circle(circle);
}