Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
Php 将GEvent addListener添加到google地图_Php_Google Maps_Map - Fatal编程技术网

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])
 }