2012-04-18 94 views
0

对于产生谷歌地图我调用该函数displayLocation下一个代码标记:只显示第一和路径最后一个标记

for (var i=0; i<data.length; i++) { 
    displayLocation(data[i]); 
} 

在displayLocation我创建一个数组与我想的路径上的所有位置创建和标记,我只想显示路径上的第一个和最后一个标记。 我displayLocation功能看起来像:

function displayLocation(location){ 
       var latLng = new google.maps.LatLng(parseFloat(location.latitud), parseFloat(location.longitud)); 
       if(location.nombreequipo=="AST1"){ 
        var path = new google.maps.LatLng(parseFloat(location.latitud), parseFloat(location.longitud)); 
        rutaAST1.push(path); 
       } 

       var marker = new google.maps.Marker({ 
        position: latLng, 
        map: map, 
        icon: imagen, 
        draggable: false, 
        visible: true, 
        title: location.nombreequipo 
       }); 
       arrayMarcadores.push(marker); 
       google.maps.event.addListener(marker, 'click', function(){ 
        infowindow.setContent(content); 
        infowindow.open(map, marker); 
       }); 
       return marker; 
      } 

在我设置路径的这部分代码,我呼吁:

varBool = true; 
dibujaRutaAST1(map, rutaAST1, varBool); 

而且功能:

var ruta = null; 
function dibujaRutaAST1(mapa, rutaVar, varBool){ 
if(!ruta){ 
    var coordRuta = rutaVar; 
    console.log("En función dibujo de rutas AST1: "+rutaVar); 
    ruta= new google.maps.Polyline({ 
     map: mapa, 
     path: coordRuta, 
     geodesic: true, 
     strokeColor: "#FF0000", 
     strokeOpacity: 1.0, 
     strokeWeight: 3 
    }); 
    console.log(ruta); 
}if(varBool){ 
    ruta.setMap(mapa); 
}else{ 
    ruta.setMap(null); 
} 
} 

上的标记迭代array:

function mostrarMarcas(nombreEquipo){ 
       for(var i=0;i<arrayMarcadores.length;i++){ 
        if(arrayMarcadores[i].title==nombreEquipo){ 
         arrayMarcadores[i].setVisible(true); 
        } 
       } 
      } 

有什么建议吗? 谢谢。

+0

在你的代码的某个部分,你用'setMap()'设置路径和标记。你能告诉我们吗? – 2012-04-18 09:42:59

+0

好吧,我看到你的更新,但我的意思是你使用'for'来迭代'arrayMarcadores'的部分。在这部分中,您可以使用第一个和最后一个元素,例如'arrayMarcadores [0]'和'arrayMarcadores [arrayMarcadores.length - 1]'。 – 2012-04-18 09:57:16

+0

对不起,我忘了那部分,谢谢你的帮助。 – lfergon 2012-04-18 10:01:14

回答

0

最后,我只是创建了第一个和我的数组中最后一个标记与所有点:

if(rutaAST1.length!=0){ 
    dibujaRutaAST1(map, rutaAST1, varBool); 
    var imagen ='img/markers/blue_MarkerA.png'; 
    var markerIniAST1 = new google.maps.Marker({ 
     position: rutaAST1[0], 
     map: map, 
     icon: imagen, 
     draggable: false, 
     visible: true, 
     title: "AST1" 
    }); 
    google.maps.event.addListener(markerIniAST1, 'click', function(){ 
     infowindow.setContent(contentAST1[0]); 
     infowindow.open(map, markerIniAST1); 
    }); 
    var markerFinAST1 = new google.maps.Marker({ 
     position: rutaAST1[rutaAST1.length-1], 
     map: map, 
     icon: imagen, 
     draggable: false, 
     visible: true, 
     title: "AST1" 
    }); 
    google.maps.event.addListener(markerFinAST1, 'click', function(){ 
     infowindow.setContent(contentAST1[contentAST1.length-1]); 
     infowindow.open(map, markerFinAST1); 
    }); 
} 

非常感谢你帮我清除我的脑海里有我的这部分代码:)

相关问题