Google Maps - Attaching InfoWindows to polygons in array

后端 未结 3 897
半阙折子戏
半阙折子戏 2021-01-21 07:46

I\'ve been banging my head against the wall all morning with this one. I an creating an array of polygons, and want to associate some data in each one that will show in an info

3条回答
  •  渐次进展
    2021-01-21 08:10

    There are a few problems that might be preventing this from working:

    1: You need a var in front of infowindow, to make it a local variable:

    var infowindow = new google.maps.InfoWindow(...
    

    As it is, you are replacing the infowindow variable every time you add a new click listener.

    2: You need to specify a position or anchor for the infowindow (see: http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindowOptions).

    The only valid anchor is a Marker, so you will probably want to specify the 'position' property. 'position' must be a valid google.maps.LatLng object. I suspect you will want to compute the center of your polygon to use as the position.

    You also need to make sure map is a global variable, although it likely is looking at the rest of your code.

提交回复
热议问题