5

Here I am using Google map API to show Google map in my site. Here I am able to add google map statically by following code:

        var map = new GMap2(document.getElementById('map'));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(21.183008, 81.36186199999997), 6);



        var marker = new GMarker(new GLatLng(21.183008, 81.36186199999997), {});
        GEvent.addListener(marker, "mouseover", function () {
            marker.openInfoWindow("Hi ");
        });
        GEvent.addListener(marker, "mouseout", function () {
            map.closeInfoWindow();
        });
        map.addOverlay(marker);           


        var marker1 = new GMarker(new GLatLng(21.25, 81.62), {});
        GEvent.addListener(marker1, "mouseover", function () {
            marker1.openInfoWindow("HI All");
        });
        GEvent.addListener(marker1, "mouseout", function () {
            map.closeInfoWindow();
        });          
        map.addOverlay(marker1);

I have set of marker value in array. When I try it to create dynamically only last information window displayed.

awaiting for response....

Ruslan Polutsygan
  • 4,401
  • 2
  • 26
  • 37
Yashwant Kumar Sahu
  • 3,356
  • 7
  • 27
  • 42
  • This sounds like a closure problem, but where is your array (and expected `for`-loop)? – Halcyon Sep 03 '11 at 14:06
  • this code is from the previous version of google maps api. v3 is up for quite a time : http://code.google.com/apis/maps/documentation/javascript/basics.html There are great sample on that page. – tugberk Sep 03 '11 at 14:40
  • can you setup a jsfiddle please.. i am nt sure what google map api i need to use – Baz1nga Sep 03 '11 at 18:20

1 Answers1

0

This has to do with closures in Javascript and it is a common problem. See the Google Maps Javascript API Docs for a solution.

And for more information about closures I would recommend you to search on Stackoverflow (like the comment here, for example) ;)

Community
  • 1
  • 1
Harmen
  • 22,092
  • 4
  • 54
  • 76