How to close any open InfoWindow's using jquery-ui-map (Google Map v3 plugin for jQuery)

2.8k views Asked by At

The user has markers loaded depending on where they select their location. The markers are cleared when a new location is chosen. If I have an InfoWindow open when I clear the markers, it stays open even though the marker goes away. I want any open InfoWindow to close when the data is refreshed.

My implementation details:

I am using jquery-ui-map to enhance my Google Maps implementation with jQuery.

I attach a click event when creating the markers with the following code (FYI: I took out all the specific details and replaced them with generic ones).

$('#map-canvas').gmap('addMarker', {
    'position' : new google.maps.LatLng(latitude, longitude),
    'title' : myTitle,
    'icon' : myImage,
    'shadow' : myShadowImage
}).click(function() {
    $('#map-canvas').gmap('openInfoWindow', {
        'content' : displayContent(myObject)
    }, this);
});

The option openInfoWindow does not return anything, so storing the InfoWindow object in an array to close it later does not look like a viable option.

Does anyone know how to achieve this using the jquery-ui-map library? I don't see a closeInfoWindow listed in the API documentation.

1

There are 1 answers

3
johansalllarsson On BEST ANSWER

jquery-ui-map v.beta

var theInfoWindowObject = $('#map_canvas').gmap('get', 'iw');
theInfoWindowObject.close();

jquery-ui-map v rc 1

$('#map_canvas').gmap('closeInfoWindow');