lfergon
lfergon

Reputation: 973

Different color markers on Google Maps

I´m trying to associate a image to 15 different teams markers on Google Maps, I´ve trying to do it, but it´s not working properly on my map, any suggestion will be appreciated. My idea is associate: if(location.nombreequipo==AST1){ icon: imagen } but I have many doubts about this idea.

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;
}

Thanks in advance.

Upvotes: 1

Views: 912

Answers (2)

lfergon
lfergon

Reputation: 973

The solution that I´ve adopted finally is:

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;
        }

Thanks.

Upvotes: 0

Heitor Chang
Heitor Chang

Reputation: 6057

Can you try adding a .imagen property to your location?

For example, assign location.imagen = img/blue.png, then

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

By the way you have two draggable, first false, then true.

Upvotes: 1

Related Questions