繁体   English   中英

使用Google Map V3 API调用infoWindow

[英]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);

});

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

试试这个,使用从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的锚点。 尝试在多边形内部或边缘的某处添加标记,setVisible(false),然后infowindow.open(map,marker)

当你说通过多边形时,我不太清楚。 我相信你可以自由地使用你的变量'折线',就像传递函数(事件)一样,可能不是。 你试过两种选择吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM