Calling infoWindow w/ Google Map V3 API



选择多边形时无法打开infoWindow。这是我的代码:

// Create Polygon
var polyline = new google.maps.Polygon({path:path, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2, clickable:false});
// Place Polygon on Map
polyline.setMap(map);
map.setCenter(new google.maps.LatLng(35.910200,-84.085100));
// Create InfoWindow object
var infowindow = new google.maps.InfoWindow({
content: ' ',
suppressMapPan:true
});
// Create Click Event for Polygon
eventPolygonClick = google.maps.event.addListener(polyline, 'click', function() {
   // Load Content 
   infowindow.setContent("CLICKED me");
   // Open Window
   infowindow.open(map, polyline);
});

我还想将多边形及其各自的内容作为变量传递给事件PolygonClick。这可能吗?

试试这个,使用从click事件接收到的latlng来创建一个标记,并将其用作infowindow.open调用中的第二个参数。

eventPolygonClick = google.maps.event.addListener(polyline, 'click', function(event) { 
   var marker = new google.maps.Marker({
      position: event.latLng
   }); 
   infowindow.setContent("CLICKED me");
   infowindow.open(map, marker);
});

就我所尝试的而言,多边形不能用作InfoWindow的锚点。尝试在多边形内部或边缘添加一个标记,设置Visible(false),然后打开信息窗口。打开(map,marker)

当你说通过多边形时,我不太明白。我相信你可以自由地使用你的变量"折线",至于用函数(事件)传递,可能不会。你试过这两种选择吗?

最新更新