我有以下代码,其中我使用显示警报的onclick侦听器初始化Polygon:
polygon.location = location;
polygon.locationLabel = new LocationLabel(location, latLng, mapProvider.map);
google.maps.event.addListener(polygon, 'click', function(e) {
alert('hello');
});
这很好,但是当我单击“多边形”但不显示实际标签时会显示警报。如何添加监听器以便在单击标签时显示警报?
答案 0 :(得分:1)
尝试:
textToShow = polygon.locationLabel;
google.maps.event.addListener(polygon, 'click', function(e, textToShow) {
alert(textToShow);
});