InfoWindow not showing on polygon click

1,113 views
Skip to first unread message

Adam Bengtson

unread,
Nov 24, 2010, 3:08:28 PM11/24/10
to google-map...@googlegroups.com
Currently I have an overlay of all of the state borders, which I am retrieving from a DB(mySQL) and drawing the polygons on to the map.  Now on click I would like info window to pop up.  Here is the click listener:

 
google.maps.event.addListener(poly, "click", function(event){
     alert('1');
      var infowindow = new google.maps.InfoWindow();
      infowindow.setContent("test");
      infowindow.setPosition(event.latLng);
      infowindow.open(map, poly);
     alert('2');
    });

I have tried many different things all with the same results pretty much.  Both alerts show up on click, but infowindow does not.  I do not get any errors either when I run this code.  All the polygons show up perfectly, as well as all of the other listeners like mouseover and mouseout work fine.

Will Cadell

unread,
Nov 24, 2010, 3:27:50 PM11/24/10
to google-map...@googlegroups.com
with out more context, my best guess is that I believe:

infowindow
.open(map, poly);

should be :

infowindow
.open(map);

cheers, w

geoco...@gmail.com

unread,
Nov 24, 2010, 6:14:16 PM11/24/10
to Google Maps JavaScript API v3
Please either read the documentation (a polygon is not a valid
"anchor" for an infowindow) or post a link to your map.

if the click resulted from a mouse click (and not a call to
"google.maps.trigger"), Will's suggestion should work (I think).

-- Larry

Adam Bengtson

unread,
Nov 25, 2010, 3:21:01 PM11/25/10
to google-map...@googlegroups.com
Hey Will thanks for the reply,

 yeah I had that originally changed it to what it is now trying to get it to work.  I tried all different variations of calling an infowindow.

Adam

Adam Bengtson

unread,
Nov 25, 2010, 3:25:51 PM11/25/10
to google-map...@googlegroups.com
I cannot link to the map or post the code due to various reasons, but the way I understood it was if you give it a position then it should show.  

Adam

Rossko

unread,
Nov 25, 2010, 3:28:08 PM11/25/10
to Google Maps JavaScript API v3
> yeah I had that originally changed it to what it is now trying to get
> it to work. I tried all different variations of calling an infowindow.

Well I guess that's the end of that, then. Unless you can provide a
link to your best effort so far?

Or you might search previous postings
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/154d1350772216fc/e2c0681d0d37c810?lnk=gst&q=infowindow+polygon#e2c0681d0d37c810

Adam Bengtson

unread,
Nov 25, 2010, 5:19:32 PM11/25/10
to google-map...@googlegroups.com
Thanks for trying, I've gone through all the those threads and copied what they have done and still get the same results.  It is on an internal network and I am not allowed to link the code.  I can add markers and the InfoWindows pop up fine, I'll just have to go with that.  Sorry about the lack of information thanks again for the help.

Adam

Rossko

unread,
Nov 26, 2010, 5:36:21 AM11/26/10
to Google Maps JavaScript API v3
> It is on an
> internal network and I am not allowed to link the code.

Sounds like you have a Premier licence, which does include support.
Contact your Google rep.

geoco...@gmail.com

unread,
Nov 26, 2010, 9:36:03 AM11/26/10
to Google Maps JavaScript API v3
Then I would suggest:
1. reading the terms of use to ensure that your application complies
2. searching the group for examples that work and seeing if a working
example helps you determine what you are doing wrong.
3. if all else fails, get a website that you can put a simple map on
that exhibits the problem; then we can help.

-- Larry

>
> Adam

Will Cadell

unread,
Nov 26, 2010, 12:53:47 PM11/26/10
to google-map...@googlegroups.com
i remember having a bit of a time getting the whole infowindow from a looped series of database driven polys thing top work first time...

here is my breakdown:

define global infowindow variable
define global polygonArray variable

call php (or whatever) function and loop through results set

>getPoly() - on each record:
  pull attributes you need
  build geometry (from attributes in record set, likely as MVC array)
 > call function to actually define polygon feature (with various attributes and geometry as arguments)this will return a polygon object
    makePoly(geometry, val1, var2)
   > makes the polygon using standard syntax, then call another function called makeClick(var1, var2)
         add the click event here using the infowindow as your base...
   >return to makePoly (polygon with click event attached)
> return to getPoly as poly with click attached
>add record to polygon array (push)
then, still in getPoly function  polygonArray[i].setMap(map)

this should leave you with an array of polys each with a click event... I hope that is useful!

remember, firebug is your friend!

good luck, w
Reply all
Reply to author
Forward
0 new messages