我想知道单击标记时如何打开信息窗口,我认为这是正确的,但不起作用。这是脚本
var map;
function initialize() {
navigator.geolocation.getCurrentPosition(function(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var coords = new google.maps.LatLng(latitude, longitude);
var mapOptions = {
disableDefaultUI: true,
center: coords,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
placeMarker();
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
getComment(marker, infowindow);
});
});
}
function getComment(marker, infowindow){
var message = "Hello";
infowindow.setContent(message);
infowindow.open(map, marker);
}
function placeMarker() {
//place some marker
}
google.maps.event.addDomListener(window, 'load', initialize);
感谢您的任何建议!