如何獲取谷歌地圖infowindow多個多邊形? 我設法得到多個多邊形,但我有問題要顯示多邊形上的每個多邊形和中心信息窗口的信息窗口。谷歌地圖 - InfoWindows多個多邊形
的jsfiddle:https://jsfiddle.net/ow8kb0vn/
var editedPolygons = [
[
[
{
"lat":14.56754606924714,
"lng":120.99225461483002
},
{
"lat":14.567213783453319,
"lng":120.9916752576828
},
{
"lat":14.566736121747363,
"lng":120.99207758903503
}
],
{
"color":"green",
"title":"---------------------------------------info content green"
}
],
[
[
{
"lat":14.566383066777853,
"lng":120.99221169948578
},
{
"lat":14.566325954891425,
"lng":120.99138557910919
},
{
"lat":14.565635419093956,
"lng":120.9915840625763
},
{
"lat":14.565635419093956,
"lng":120.9925840625763
}
],
{
"color":"red",
"title":"----------------------------------------------info content red"
}
]
];
var map;
function initialize() {
var mapProp = {
center: new google.maps.LatLng(14.5667, 120.9927),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
for (var i = 0; i < editedPolygons.length; i++) {
var poly = new google.maps.Polygon({
\t fillColor: editedPolygons[i][1].color,
\t \t strokeWeight: 2,
path: editedPolygons[i][0],
map: map
});
\t \t var infowindow = new google.maps.InfoWindow({
\t \t \t content: editedPolygons[i][1].title
\t \t \t });
\t \t poly.addListener('click', function() {
\t \t \t infowindow.open(map, poly);
\t \t \t });
}
}
google.maps.event.addDomListener(window, "load", initialize);
html, body, #googleMap {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,drawing&ext=.js"></script>
<div id="googleMap"></div>
謝謝,但還有一個問題。如何在多邊形內點擊/錄製位置顯示infowindow? – akuljana
使用事件latLng – geocodezip
我嘗試** infoWindow.setPosition(event.latLng)**但沒有運氣。如何從你的解決方案中得到這個? – akuljana