2012-03-20 136 views
0

虽然开发这一解决方案,我才知道,API V2是被弃用。我从此开始使用API​​ V3的版本。该工作正在进行中,您可以在My New Map找到。特别感谢大卫马兰在Hammerspace加速这个转换对我来说。谷歌地图API V3的信息窗口

我到其余3 issues..the其中第一个我将在这篇文章中解决。

我无法触发信息窗口我已经定义:

google.maps.event.addListener(polyline, 'click', function(event) { 
    if (polyline.Contains(event.latLng)) { 
     infowindowInside.open(map,polyline); 
    } else { 
     infowindowOutside.open(map,polyline); 
    } 
    }); 

我将它们连接到polygon..not标记。多边形是这样写的:

var path = [ 
new google.maps.LatLng(35.950079, -84.104977), 
new google.maps.LatLng(35.950774, -84.049702), 
new google.maps.LatLng(35.946883, -84.047813), 
new google.maps.LatLng(35.945354, -84.045067), 
new google.maps.LatLng(35.940907, -84.042149), 
new google.maps.LatLng(35.930483, -84.037857), 
new google.maps.LatLng(35.939656, -84.037857), 
new google.maps.LatLng(35.928120, -84.076309), 
new google.maps.LatLng(35.938822, -84.066868), 
new google.maps.LatLng(35.950079, -84.104977)]; 
var polyline = new google.maps.Polygon({path:path, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2, clickable:false}); 
polyline.setMap(map); 

我很感激你可以提供的任何指导。

谢谢。

**修订* ** * *

现在我已经修改了代码:

google.maps.event.addListener(polyline, 'click', function(event) { 
    if (polyline.ContainsLocation(event.latLng, polyline)) { 
     window.alert('inside');//infowindowInside.open(map,polyline); 
    } else { 
     window.alert('outside');//infowindowOutside.open(map,polyline); 
    } 
    }); 

However..still没有触发。

回答

2

可能是因为Polygon没有一个“包含”功能。你应该看看在使用谷歌地图API Geometry Library,其中有一个containsLocation功能。

+0

感谢,@Mano商标。请参阅我上面更新的内容。 – mcmonty 2012-03-21 15:09:30

1

谷歌地图API V3不允许你信息窗口添加到折线或多边形。解决这个问题的解决办法就是抓住鼠标点击的纬度/经度坐标和信息窗口(用户点击他/她的鼠标)附加到地图,如:

google.maps.event.addListener(polyline, 'click', function(event) { 
if (polyline.Contains(event.latLng)) { 
    infowindowInside.open(map); 
} else { 
    infowindowOutside.open(map); 
} 
}); 

(注意如何不存在在。开()方法的第二个参数)

否则,你可以找出你的多边形无论是中心还是它的一个角落的纬度/经度和附加信息窗口出现(但地图)

这将允许您显示您的infowindow,同时使其显示为与多边形相连。

编辑:另外 - 正如马诺马克已经说过的.Contains-我不确定该方法是否存在,以至于即使在从第二个参数中删除第二个参数后,您的代码块仍可能不起作用.open()方法。如果出现这种情况,您可能需要采用不同的方法来处理逻辑,但将标记附加到地图而不是多边形或折线将解决您的主要问题。

相关问题