通过@geocodezip的评论,我得到了解决方案。它并不完美,InfoWindow
始于标记的脚下而不是头部,但它是某种东西。
var infoWindow;
var map;
function initialize() {
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
var opts = {suppressInfoWindows: true};
var kmlLayer = new google.maps.KmlLayer('https://maps.google.com/maps/ms?authuser=0&vps=2&ie=UTF8&msa=0&output=kml&msid=209879288832578501414.0004c52d678cf88f70685', opts);
kmlLayer.setMap(map);
infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(kmlLayer, 'click', function(kmlMouseEvent) {
var name = kmlMouseEvent.featureData.name;
var descr = kmlMouseEvent.featureData.description.replace(/ target="_blank"/ig, '');
var dom = '<div style="font-family: Arial, sans-serif; font-size: small">' +
'<div style="font-weight: bold; font-size: medium; margin-bottom: 0em">' +
name +
'</div>' +
'<div>' +
descr +
'</div>' +
'</div>';
infoWindow.setContent(dom);
infoWindow.setPosition(kmlMouseEvent.latLng);
infoWindow.open(map);
});
}