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