gpt4 book ai didi

javascript - 使用 Google Map V3 API 调用 infoWindow

转载 作者:行者123 更新时间:2023-11-30 13:21:52 25 4
gpt4 key购买 nike

当我选择多边形时无法打开信息窗口。这是我的代码:

// 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。这可能吗?

最佳答案

试试这个,使用从点击事件收到的 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);

});

关于javascript - 使用 Google Map V3 API 调用 infoWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9998003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com