You can have a global variable to keep track of the infowindow and close it before opening new one using the close()
method, something like
var infoWindow; //global tracker
function showpopup(lat, lng, info)
{
//close info window in it exists
if(infoWindow)
infoWindow.close();
// Create new infoWindow
infoWindow = new google.maps.InfoWindow({
content: info
});
// Create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
title: 'Lima',
map: map.map,
infoWindow: infoWindow
});
// This opens the infoWindow
infoWindow.open(map, marker);
}
If there are more then one info windows, you can have an array, loop through them and call the close()
method on each item..