2012-04-13 19 views
1

Googleマップの15種類のチームマーカーに画像を関連付けようとしていますが、これをやろうとしていますが、地図上で正しく機能していないため、 。私の考えはアソシエイトです:if(location.nombreequipo == AST1){icon:imagen}しかし、私はこのアイディアについて多くの疑念を持っています。Googleマップの色マーカーが異なる

function displayLocation(location){ 
    var content = '<strong><p>Equipo: ' +location.nombreequipo + '</strong>' 
     +'</strong></p><strong><p>Hora móvil: ' + location.fecha_movil 
     + '</strong></p><strong><p>Longitud: ' +location.longitud +'</strong></p>' 
     + '</strong></p><strong><p>Latitud: ' +location.latitud +'</strong></p>'; 
    var latLng = new google.maps.LatLng(parseFloat(location.latitud), parseFloat(location.longitud)); 
    var imagen ='img/blue_MarkerA.png'; 
    var marker = new google.maps.Marker({ 
     position: latLng, 
     draggable: false, 
     map: map, 
     draggable: true, 
     visible: true, 
     title: location.nombreequipo 
    }); 
    arrayMarcadores.push(marker); 
    google.maps.event.addListener(marker, 'click', function(){ 
     infowindow.setContent(content); 
     infowindow.open(map, marker); 
    }); 
    return marker; 
} 

ありがとうございます。

答えて

1

location.imagenプロパティを追加できますか?

たとえば、あなたは真の最初の偽の2 draggableを、持っていた後、location.imagen = img/blue.pngところで

  var marker = new google.maps.Marker({ 
       position: latLng, 
       draggable: false, 
       ... 
       icon: location.imagen 
      }); 

を割り当てます。

+0

ああ、そのミスについて申し訳ありません、ついに私は別の方法で解決しました。しかしあなたの考えは本当に良いです。 – lfergon

0

I'veが最終的に採用されている解決策:

if(location.nombreequipo=="TEAMNAME"){ 
    var image='img/blueMarker.png'; 
} 
if(location.nombreequipo=="TEAMNAME2"){ 
    var image='img/redMarker.png'; 
} 
function displayLocation(location){ 
      var content = '<strong><p>Equipo: ' +location.nombreequipo + '</strong>' 
       +'</strong></p><strong><p>Hora móvil: ' + location.fecha_movil 
       + '</strong></p><strong><p>Longitud: ' +location.longitud +'</strong></p>' 
       + '</strong></p><strong><p>Latitud: ' +location.latitud +'</strong></p>'; 
      var latLng = new google.maps.LatLng(parseFloat(location.latitud), parseFloat(location.longitud)); 
      var marker = new google.maps.Marker({ 
       position: latLng, 
       map: map, 
       draggable: true, 
       visible: true, 
       title: location.nombreequipo, 
       icon: image 
      }); 
      arrayMarcadores.push(marker); 
      /*Content window asociated to created markers*/ 
      google.maps.event.addListener(marker, 'click', function(){ 
       infowindow.setContent(content); 
       infowindow.open(map, marker); 
      }); 
      return marker; 
     } 

感謝を。

関連する問題