Php 将GEvent addListener添加到google地图
谁能帮我一下吗 我想将Php 将GEvent addListener添加到google地图,php,google-maps,map,Php,Google Maps,Map,谁能帮我一下吗 我想将GEvent.addListener添加到地图中的每个标记,但不起作用。我尝试了很多方法,但没有结果,请您帮忙 我认为代码只保留循环中的最后一个标记 您可以在线查看我的工作,网址为: 函数getIcon_Comunita(){ var icon=new GIcon(); icon.image=“/include/png/com_locali.png”; icon.iconAnchor=新的GPoint(48,48); icon.infoWindowAnchor=新的GPo
GEvent.addListener
添加到地图中的每个标记,但不起作用。我尝试了很多方法,但没有结果,请您帮忙
我认为代码只保留循环中的最后一个标记
您可以在线查看我的工作,网址为:
函数getIcon_Comunita(){
var icon=new GIcon();
icon.image=“/include/png/com_locali.png”;
icon.iconAnchor=新的GPoint(48,48);
icon.infoWindowAnchor=新的GPoint(16,0);
icon.iconSize=新的GSize(30,34);
返回图标;
}
var-map1;
函数map1\u初始化(){
if(google.maps.BrowserIsCompatible())
{
map1=新的google.maps.Map2(document.getElementById('map1div');
addControl(新的google.maps.LargeMapControl3D());
addControl(新的google.maps.MenuMapTypeControl());
地图1.setCenter(新的google.maps.LatLng(0,0),0);
var latlng=[
新的google.maps.LatLng(parseFloat(),parseFloat()),
];
对于(变量i=0;i
每次迭代时,您都会覆盖此处的变量标记:
for ( var i = 0; i < latlng.length; i++ )
{
var marker = new google.maps.Marker( latlng[ i ],getIcon_Comunita());
GEvent.addListener(marker, "click", function () {
map1.setZoom(map1.getZoom() + 1);
marker.openInfoWindowHtml("This the coordinate of this point"+marker+"yups");
});
map1.addOverlay( marker );
}
for(变量i=0;i
要解决此问题,可以在循环中使用匿名函数:
for ( var i = 0; i < latlng.length; i++ )
{
(
function(latlng){
var marker=new google.maps.Marker( latlng,getIcon_Comunita());
GEvent.addListener(marker, "click", function () {
map1.setZoom(map1.getZoom() + 1);
marker.openInfoWindowHtml("This the coordinate of this point:"
+latlng.toUrlValue());
});
map1.addOverlay(marker);
})(latlng[i])
}
for(变量i=0;i
for ( var i = 0; i < latlng.length; i++ )
{
(
function(latlng){
var marker=new google.maps.Marker( latlng,getIcon_Comunita());
GEvent.addListener(marker, "click", function () {
map1.setZoom(map1.getZoom() + 1);
marker.openInfoWindowHtml("This the coordinate of this point:"
+latlng.toUrlValue());
});
map1.addOverlay(marker);
})(latlng[i])
}