问题描述
我试图让这个人点击地图,并且一个infoWindow弹出来告诉他们那个latlng。现在,试图找出如何让infoWindow出现。我在这里用标记发现了一个类似的问题,并且编辑了一些函数,但是我错过了一些我很确定很简单的东西,但我不能指出。以下是代码:
函数InfoWindow(位置){
if(marker){
marker.setPosition (位置);
} else {
marker = new google.maps.infoWindow({
position:location,
content:sam
});
google.maps.event.addListener(map,'click',function(event){
InfoWindow(event.latLng);
});
}
非常感谢!
Thanks
有一个latLng属性
google.maps。 event.addListener(map,'click',function(event)
{
new google.maps.InfoWindow({
map:map,
content:coordinates:+ event.latLng.toUrlValue(),
position:event.latLng});});
map是对您的google.maps.Map的引用。
通过粘贴进行测试然后点击地图:
javascript:google.maps.event.addListener(map,'click ',function(event){new google.maps.InfoWindow({map:map,content:coordinates:+ event.latLng.toUrlValue(),position:event.latLng});});
I'm trying to have this so that someone clicks on the map, and an infoWindow pops up telling them that latlng. For now, just trying to figure out how to get an infoWindow to come up. I found a similar problem here with markers and edited the function a bit but I'm missing something which I'm sure is simple and I just cannot pin point. Here's the code:
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);
});
}
Help greatly appreciated!Thanks
The Map MouseEvent has a latLng property
google.maps.event.addListener(map, 'click', function(event)
{
new google.maps.InfoWindow({
map:map,
content:"coordinates:"+event.latLng.toUrlValue(),
position:event.latLng});});
}
"map" is a reference to your google.maps.Map.
Tested on this map by pasting this into the address bar, then clicking on the map:
javascript:google.maps.event.addListener(map, 'click', function(event) {new google.maps.InfoWindow({map:map, content:"coordinates:"+event.latLng.toUrlValue(),position:event.latLng});});
这篇关于InfoWindow不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!