google maps v3 marker title property
In my function I am looping through an array of states and placing markers in the center of each state. I want each marker tooltip to display its specific information. However, for some reason when I mouse over the markers a tooltip doesn't popup over any of them even though I instantiated the marker with the title property.
see code below:
mark = new google.maps.Marker({
开发者_JAVA技巧 map: map,
position: center,
title:inspStates[i].name+ "<br/>"+"total: "+inspStates[i].totalInsp+ "<br/>"+ info
});
what is my error?
You have error in your code
title:inspStates[i].name+ "
"+"total: "+inspStates[i].totalInsp+ "
"+ info;
The trailing semicolon is mistaken. You are defining an object property but not the simple variable.
2. According to your code all markers will be shown at same place(Of course, if center
is not being defined each loop iteration)
position: center
Maybe there should be something like this inspStates[i].position
?
UPD
Here is my code sample.
var places=[
{
position: new google.maps.LatLng(51.5220975, -0.1702880859375),
name: 'first place'
},
{
position: new google.maps.LatLng(51.51, -0.1714),
name: 'second place'
},
{
position: new google.maps.LatLng(51.52205918460975, -0.17380859375),
name: 'third place'
}
];
for(var i=0, len=places.length; i<len; i++)
{
var marker = new google.maps.Marker({
map: map,
position: places[i].position,
title: places[i].name
});
}
Maybe it will be helpfull. Three markers with predifined titles has been shown by this code. Is your code like my? Also one question: Is variable center
from your code being changed each loop itaration. I have talked about it but oyu haven't commented it.
Could you please post your code sample to get more help?
I had set the disableDefaultUI to true which apparently caused the tooltips not to be shown. When I reenabled it all the markers had a tooltip with the proper information.
精彩评论