if I don't use the function createMarker() ,(it has been annotated),
I can't addlistener to each marker! why???
the same statements i used in for() statement , can only open a single
InfoWindow ,But if i use the function createMarker() ,i can open
infowinow by click each marker.
code like this:
var map1;
function initial()
{
if(GBrowserIsCompatible())
{
map1 = new GMap2(document.getElementById("id1"));
center= new GLatLng(39.917, 116.397);
map1.setCenter(center,14);
map1.enableScrollWheelZoom();
map1.addControl(new GLargeMapControl());
map1.addControl(new GMapTypeControl());
setmarkerbybound();
}
/*function createMarker(latlng, number) {
var marker = new GMarker(latlng);
GEvent.addListener(marker,"click", function() {
var myHtml = "<b>#" + number + "</b><br/>" ;
map1.openInfoWindowHtml(latlng, myHtml);
});
return marker;
}*/
function setmarkerbybound()
{
var bounds=map1.getBounds();
var SouthWest=bounds.getSouthWest();
var NorthEast=bounds.getNorthEast();
var latspan=NorthEast.lat()-SouthWest.lat();
var lngspan=NorthEast.lng()-SouthWest.lng();
for(var i=0;i<10;i++)
{
var point=new GLatLng(SouthWest.lat()
+latspan*Math.random(),
SouthWest.lng()
+lngspan*Math.random());
/*map1.addOverlay(createMarker(point,i));*/
var marker = new GMarker(point);
map1.addOverlay(marker);
GEvent.addListener(marker,"click",function(){
var myhtml=i+"this is
a test";
map1.openInfoWindowHtml
(point,myhtml)});
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---