Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌地图:获取功能中的点击位置_Javascript_Google Maps - Fatal编程技术网

Javascript 谷歌地图:获取功能中的点击位置

Javascript 谷歌地图:获取功能中的点击位置,javascript,google-maps,Javascript,Google Maps,我允许用户在谷歌地图中创建、编辑和删除多边形。用户可以决定为每个多边形输入文本,单击多边形时,文本将显示在信息窗口中。下面的代码显示了这是如何实现的。我的问题是,我目前无法检测点击事件的位置-我需要知道这一点,因为这是信息窗口将显示的位置。我试过很多方法来完成这项工作 在下面的代码中,tmfPolygonObjects[i][9]包含要在信息窗口中显示的文本 我需要在函数中捕获事件,但无法解决此问题。任何建议都是非常欢迎的 function tmfAddPolygonInfoWindowList

我允许用户在谷歌地图中创建、编辑和删除多边形。用户可以决定为每个多边形输入文本,单击多边形时,文本将显示在信息窗口中。下面的代码显示了这是如何实现的。我的问题是,我目前无法检测点击事件的位置-我需要知道这一点,因为这是信息窗口将显示的位置。我试过很多方法来完成这项工作

在下面的代码中,tmfPolygonObjects[i][9]包含要在信息窗口中显示的文本

我需要在函数中捕获事件,但无法解决此问题。任何建议都是非常欢迎的

function tmfAddPolygonInfoWindowListener(myPolygon, i, myPolygonInfoWindow) { 
  tmfPolygon = myPolygon;
  tmfPolygonInfoWindow = myPolygonInfoWindow;
  tmfShowPolygonInfoWindowListener[i] = google.maps.event.addListener(tmfPolygon, 'click', (function(tmfPolygon, i) {
      return function() {
              tmfPolygonInfoWindow.setContent(tmfPolygonObjects[i][9]);

              // this is where I would set the position of the info window IF I could detect the event
              tmfPolygonInfoWindow.setPosition(event.latLng()); 
              tmfPolygonInfoWindow.open(map, tmfPolygon);
          }
      }
  })(tmfPolygon, i));
}

我自己设法解决了这个问题。只需将“事件”添加到返回函数()。更新的代码如下所示

function tmfAddPolygonInfoWindowListener(myPolygon, i, myPolygonInfoWindow) { 

tmfPolygon = myPolygon;
  tmfPolygonInfoWindow = myPolygonInfoWindow;
  tmfShowPolygonInfoWindowListener[i] = google.maps.event.addListener(tmfPolygon, 'click', (function(tmfPolygon, i) {
      return function(event) {
              tmfPolygonInfoWindow.setContent(tmfPolygonObjects[i][9]);

          // this is where I would set the position of the info window IF I could detect the event
          tmfPolygonInfoWindow.setPosition(event.latLng); 
          tmfPolygonInfoWindow.open(map, tmfPolygon);
      }
  }
  })(tmfPolygon, i));
}