Answer the question
In order to leave comments, you need to log in
How to color a single marker from many on one layer in google maps?
Everyone is good!
There is a map on Google
There is a table with addresses and a sign of friend or foe (red or green)
I import data from the table to the layer
Question - how to paint markers in different colors (red and green), depending on the sign in the table?
or in extreme cases - how to manually color them?
And then you change the color on one, and everyone changes (
Thanks in advance
Answer the question
In order to leave comments, you need to log in
Compose an array of objects from this table like this:
const map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-33.91722, 151.23064),
zoom: 16
});
const markers = [
{
type: '', // тут свой алиас для красного и зелёного
position: {
lat: '55.0000',
lng: '55.0000'
}
},
{
type: '', // тут свой алиас для красного и зелёного
position: {
lat: '55.0000',
lng: '55.0000'
}
},
{
type: '', // тут свой алиас для красного и зелёного
position: {
lat: '55.0000',
lng: '55.0000'
}
}
];
markers.forEach(data => {
const marker = new google.maps.Marker({
position: data.position,
icon: data.type === 'алиас' ? 'путь к одной иконке' : 'или другой',
map: map
});
}
Each layer maintains its own color. Unfortunately import to My Maps does not support multiple layers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question