我有信息窗口的问题。当我点击地图时我创建了标记,但我也想显示信息窗口。此代码不适用于此部分:
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
这是下面的代码..感谢您的帮助
var pridat;
var map;
function initialize() {
var locc = new google.maps.LatLng(49.938682,17.903331);
var mapOptions = {
zoom: 14,
center: locc,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
var contentwindow = '<div>your point</div>'
var infowindow = new google.maps.InfoWindow({
content: contentwindow
});
// IF I REMOVE THIS PART -> IT WORKS, BUT WITHOUT INFOWINDOW
google.maps.event.addListener(marker, 'click', function(){
infowindow.open(map, marker);
});
// END OF PART
google.maps.event.addListener(map, 'rightclick', function(event) {
placeMarker(event.latLng);
});
}
function placeMarker(location) {
if (marker) {
marker.setPosition(location);
} else {
marker = new google.maps.Marker({
position: location,
map: map,
title: 'My point',
draggable: true,
});
}
}