Google Visualization API Geomap: How to handle marker click events?

4.6k views Asked by At

I initially have the Google Visualization API Geomap on a world view (options['dataMode'] = 'regions') and I capture the 'regionClick' event when a country is clicked like so:

google.visualization.events.addListener(
    geomap, 'regionClick', function (e) {
        var rowindex = data.getFilteredRows([{column: 0, value: e['region']}]);  
        var location = data.getValue(rowindex[0], 3);
        location.href = "?ISO=" + e['region'] + "&Location=" + location;
    });

I then draw the map zoomed into the country in markers mode (options['dataMode'] = 'markers'). However, I can't seem to capture any events when the markers themselves are clicked.

The documentation ( http://code.google.com/apis/visualization/documentation/gallery/geomap.html#Events ) only refers to 'select' and 'regionClick' events neither of which are fired in this case. (Tested using Chrome 9, and IE 8.)

Has anybody had any success in doing this? Many thanks.

2

There are 2 answers

0
Carlos da Costa On BEST ANSWER
3
ardila On

I have it working on IE 8 and Chrome. First off, note the warning in the documentation if you are running this locally as file://

If that's not the case, make sure your google.visualization.GeoMap variable (the first argument to addListener) is indeed named geomap . If it is, add an alert() as the first line of code in the event handler and see if that fires. Lastly, note that unless the variable data is global, it will be out of scope if you try to access it from the event handler as you are doing.