Page 1 of 1

google map: close opened infowindow when loading new markers...

Posted: Mon Sep 17, 2012 8:34 am
by John4930205

I have below code to display markers on Google map using select menu. The below code is applied to mobileselectmenu - value change -run custom javascript.

Everything is working fine, but when one of infowindow is open and I choose a new selection in select menu, the opened infowindow is still showing...

How can I make sure all previous opened infowindow hides/closes when selecting a new menu selection?

-----------------------

var map = Tiggr('googlemap1');
map.options['address']='';
map.refresh();

var myVar = Tiggr('mobileselectmenu1').val();

if (myVar == "A1"){

var myLatlng = new google.maps.LatLng(21.291334, -157.840791);
var mapOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var marker1 = new google.maps.Marker({
position: myLatlng,
title: "Testmarker1"
});
var infowindow = new google.maps.InfoWindow();
//clicklistener
google.maps.event.addListener(marker1, 'click', function() {
infowindow.close();
infowindow.setContent('Marker #1');
infowindow.open(Tiggr("googlemap1").gmap, marker1);
});
Tiggr("googlemap1").options.mapElement.gmap('addMarker', marker1);
Tiggr("googlemap1").options.mapElement.gmap(mapOptions);
Tiggr("googlemap1").options.mapElement.gmap("refresh");

} else if (myVar == "A3"){

var myLatlng = new google.maps.LatLng(21.290594,-157.835598);
var mapOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var marker3 = new google.maps.Marker({
position: myLatlng,
title: "Testmarker3"
});
var infowindow = new google.maps.InfoWindow();
//clicklistener
google.maps.event.addListener(marker3, 'click', function() {
infowindow.close();
infowindow.setContent('Marker #3');
infowindow.open(Tiggr("googlemap1").gmap, marker3);
});
Tiggr("googlemap1").options.mapElement.gmap('addMarker', marker3);
Tiggr("googlemap1").options.mapElement.gmap(mapOptions);
Tiggr("googlemap1").options.mapElement.gmap("refresh");

}


google map: close opened infowindow when loading new markers...

Posted: Tue Sep 18, 2012 1:11 am
by maxkatz

The best is to check if there is Google Map API to do that...