Change Google Maps default pin color

Asked

Viewed 579 times

1

Good morning guys, it’s my first question here, so if I do anything out of the norm I apologize in advance.

Need to change the default color of the google maps pin to some hexadecimal value, would it be possible? I already anticipate that I can not create pngs of each color and search for a url because the color comes from the database.

inserir a descrição da imagem aqui

Follow my code below:

var marcador = new MarkerWithLabel
({
  position    : {lat: parseFloat (dados.latitude), lng: parseFloat (dados.longitude)},
  raiseOnDrag : true,
  map         : mapa,
  icon        : // preciso fazer algo aqui para que o pin assuma a co com base no hexadecimal que vem da variável
  visible     : true
});

Thanks in advance

1 answer

1

There are some different color markers that you can use; blue, red, purple, yellow, green.

So you can use the structure that you put in the question and put one of these markers as icon:

var marcador = new MarkerWithLabel
({
  position    : {lat: parseFloat (dados.latitude), lng: parseFloat (dados.longitude)},
  raiseOnDrag : true,
  map         : mapa,
  icon        : 'http://maps.google.com/mapfiles/ms/icons/yellow-dot.png hexadecimal'
  visible     : true
});

You can take a look in this answer of soen which is more or less what you intend to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.