1
I have an app that uses a Google map and shows multiple markers.
Next to the map I list the addresses and I would like to, when the user gave a mouseover
for each address, the map icon changes.
So I have (to show the markers):
for (var i = 0; i < lat.length-1; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat[i], long[i]),id:i, title: nomes[i], icon: pinImage, label: {text: ""+(i+1)+"", color: "white"} ,
map: map
});
And I have (to capture the mouseover
on the link):
$("a[data-link]").mouseover(function() {
var idNumber = $(this).data("link");
var novocentro = new google.maps.LatLng(lat[idNumber-1], long[idNumber-1]);
map.setZoom(14);
map.setCenter(novocentro);
});
I can already center the map to the location and zoom in. But I can’t change the Marker ICON. Imagine I could do something like this:
marker[idNumber].setIcon = "xxxx"
But it doesn’t work.
Thanks for the help! But there’s still something missing. I’m wondering, minute ....
– Henrique Burity
If I put just below map.setCenter(newcontrol); this: Marker[Idnumber]. setIcon('namepaint'); (just to see the result), the console returns an error like this: Uncaught Typeerror: Cannot read Property 'setIcon' of Undefined This snippet is inside the INITMAP function, to be included. The same problem happens if I call for example var val = Marker[1]. get("title"); It seems not to recognize MARKER. But it recognizes "map", pq map.setCenter(newcontrol) works.
– Henrique Burity
Your variable
marker
does not exist in the context of the function. When creating markers, you must assign in an Array each, so,arrayMarkers[idNumber].setIcon('nomedoicone');
. For the functionsetIcon
belongs to a Marker only.– Douglas Garrido
It worked!! I created an array, I played every single Marketer inside and then I just did this: markers[Idnumber-1]. setIcon(pinImagehover); Thank you very much for your help!!
– Henrique Burity
Good! Please mark the answer as valid. See more!
– Douglas Garrido