Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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_Google Maps Api 3_Maps - Fatal编程技术网

Javascript 仅显示给定半径内的标记

Javascript 仅显示给定半径内的标记,javascript,google-maps,google-maps-api-3,maps,Javascript,Google Maps,Google Maps Api 3,Maps,我试图制作一个只在给定半径内显示标记的算法这是我的代码: for(i=0;i

我试图制作一个只在给定半径内显示标记的算法这是我的代码:

for(i=0;i}
为每个标记创建新对象并使用该对象

见下文:

 //here use the var keyword and a new marker object
var marker[i] = new google.maps.Marker({
         position: position,
         map: map,
         title: markers[i][4].toString().concat(' ').concat(markers[i][5].toString()),
         icon: icon, 
         url:'im:<sip:'+markers[i][6]+'>'
     });

     if(<?=$this->translate($this->layout()->is_super_admin)?>==0){ 
         marker[i].setVisible(false);
        $(document).ready(function() {
            $('#select-distance').change(function() {
             var e = document.getElementById("select-distance");
             var value =  parseInt(e.options[e.selectedIndex].value);
             if(d < value){                     
                marker[i].setVisible(true);
             }else{
                marker[i].setVisible(false); 
             }
             circle.setRadius(value);
             circle.bindTo('center', markerc, 'position');
             find_closest_marker(value);  
           });
        });
//这里使用var关键字和一个新的标记对象
var marker[i]=新的google.maps.marker({
职位:职位,,
地图:地图,
标题:标记[i][4].toString().concat(“”).concat(标记[i][5].toString()),
图标:图标,
url:'im:'
});
如果(=0){
标记[i].setVisible(假);
$(文档).ready(函数(){
$(“#选择距离”)。更改(函数(){
var e=document.getElementById(“选择距离”);
var value=parseInt(e.options[e.selectedIndex].value);
如果(d<值){
标记[i].setVisible(真);
}否则{
标记[i].setVisible(假);
}
圆。设定半径(值);
圆圈.bindTo('center',markerc',position');
查找最近的标记(值);
});
});

每次都使用同一个对象,因此它将替换上一个对象。这就是为什么它只绘制最后一个标记。

为每个标记创建新对象并使用该对象

见下文:

 //here use the var keyword and a new marker object
var marker[i] = new google.maps.Marker({
         position: position,
         map: map,
         title: markers[i][4].toString().concat(' ').concat(markers[i][5].toString()),
         icon: icon, 
         url:'im:<sip:'+markers[i][6]+'>'
     });

     if(<?=$this->translate($this->layout()->is_super_admin)?>==0){ 
         marker[i].setVisible(false);
        $(document).ready(function() {
            $('#select-distance').change(function() {
             var e = document.getElementById("select-distance");
             var value =  parseInt(e.options[e.selectedIndex].value);
             if(d < value){                     
                marker[i].setVisible(true);
             }else{
                marker[i].setVisible(false); 
             }
             circle.setRadius(value);
             circle.bindTo('center', markerc, 'position');
             find_closest_marker(value);  
           });
        });
//这里使用var关键字和一个新的标记对象
var marker[i]=新的google.maps.marker({
职位:职位,,
地图:地图,
标题:标记[i][4].toString().concat(“”).concat(标记[i][5].toString()),
图标:图标,
url:'im:'
});
如果(=0){
标记[i].setVisible(假);
$(文档).ready(函数(){
$(“#选择距离”)。更改(函数(){
var e=document.getElementById(“选择距离”);
var value=parseInt(e.options[e.selectedIndex].value);
如果(d<值){
标记[i].setVisible(真);
}否则{
标记[i].setVisible(假);
}
圆。设定半径(值);
圆圈.bindTo('center',markerc',position');
查找最近的标记(值);
});
});

您每次都在使用同一个对象,因此它将替换上一个对象。这就是为什么它只绘制最后一个标记。

我未捕获类型错误时出现此错误:无法读取未定义的属性“addListener!!!!@samersboui和获取此错误的行。var infowindow=new google.maps.infowindow({content:'});marker[i].addListener('mouseover',function(){infowindow.setContent('Name:'+this.title+'

'+'');infowindow.open(map,this);});bounds.extend(position);}map.fitbunds(bounds);我将其从marker.addListener编辑到marker[i].addListener和我出现新错误:无法同时读取未定义的属性“0”ligne@samersboui删除
[i]后重试
从marker并只添加var关键字only我未捕获类型错误:无法读取未定义的属性'addListener'!!@samersboui和获取此错误的行。var infowindow=new google.maps.infowindow({content:'});marker[i].addListener('mouseover',function(){infowindow.setContent('Name:'+this.title+'

'+'');infowindow.open(map,this);});bounds.extend(position);}map.fitbunds(bounds);我将其从marker.addListener编辑到marker[i].addListener和我出现新错误:无法同时读取未定义的属性“0”ligne@samersboui尝试从标记中删除
[i]
,只添加var关键字