我正在尝试这样做,以便有人在地图上单击,然后弹出一个infoWindow,告诉他们延迟了。现在,我只是想弄清楚如何让infoWindow出现。我在这里发现了标记的类似问题,并对函数进行了一些编辑,但我遗漏了一些东西,我确信这些东西很简单,我就是无法定位。代码如下:
function InfoWindow(location) {
if ( marker ) {
marker.setPosition(location);
} else {
marker = new google.maps.infoWindow({
position: location,
content: "sam"
});
}
}
google.maps.event.addListener(map, 'click', function(event) {
InfoWindow(event.latLng);
});
}非常感谢您的帮助!谢谢
发布于 2012-07-26 21:59:24
我正在使用InfoBubble,它看起来比InfoWindow更好,而且处理起来也更容易。试试看。
发布于 2012-07-26 22:03:36
事件是一个LatLng
google.maps.event.addListener(map, 'click', function(event) {
InfoWindow(event);
});发布于 2012-07-26 22:48:09
您正确地传递了事件的LatLng (event.latLng),而不是整个事件。为了帮助输出,我包含了将lat和lng拆分成字符串的代码。我修复了其他几件事:在google.maps.InfoWindow中需要大写"I“;如果窗口已经存在,则将内容设置为新的latLng;添加了在结束时实际打开窗口的代码。这个应该会帮你解决所有的问题
function InfoWindow(location) {
var lat = location.lat().toString();
var lng = location.lng().toString();
var new_content = "Lat: " + lat + "<br />Long: " + lng
if ( marker ) {
marker.setPosition(location);
marker.setContent(new_content);
} else {
marker = new google.maps.InfoWindow({
position: location,
content: new_content
});
}
marker.open(map);
}
google.maps.event.addListener(map, 'click', function(event) {
InfoWindow(event.latLng);
});https://stackoverflow.com/questions/11670733
复制相似问题