我需要打开所有的infoWindows,我希望答案是在C#中,但我试过这个
function myMap() {
var mapProp= {
center:new google.maps.LatLng(36.109667, 43.3575),
zoom:9,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var locations={[36.3518, 43.3793],
[35.7981, 43.2932],
[36.1791, 43.4000],
[36.3518, 43.3793],
[35.7981, 43.2932],
[36.1791, 43.4000],
[36.3518, 43.3793],
[35.7981, 43.2932],
[36.1791, 43.4000]}
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
var infowindow = new google.maps.InfoWindow({
content: locations[i][0],
maxWidth: 160
});
infowindow.open(map, marker);}
}
答案 0 :(得分:2)
<div id="googleMap"></div>
<style>
#googleMap {
width: 100%;
height: 80%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?callback=myMap" async defer></script>
<script type="text/javascript">
function myMap() {
var mapProp= {
center:new google.maps.LatLng(36.109667, 43.3575),
zoom:9,
};
var map=new google.maps.Map(document.getElementById("googleMap"), mapProp);
var locations = [
[36.3518, 43.3793, "My location A"],
[35.7981, 43.2932, "My location B"],
[36.1791, 43.4000, "My location C"],
[36.3518, 43.3793, "My location D"],
[35.7981, 43.2932, "My location E"],
[36.1791, 43.4000, "My location F"],
[36.3518, 43.3793, "My location G"],
[35.7981, 43.2932, "My location H"],
[36.1791, 43.4000, "My location I"]
];
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][0], locations[i][1]),
map: map
});
var infowindow = new google.maps.InfoWindow({
content: locations[i][2],
maxWidth: 160
});
infowindow.open(map, marker);
}
}
</script>