本文介绍了InfoWindow不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让这个人点击地图,并且一个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不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 06:22