www.webdeveloper.com
Results 1 to 2 of 2

Thread: passing var into event

  1. #1
    Join Date
    Jan 2011
    Posts
    2

    passing var into event

    Hi all,

    I am currently trying to implement google maps, but I encounter a fundamental problem. I have the following peaco of code:

    Code:
    		for ( var i = 0; i < locations.length; i++) {
    			
    			var location = locations[i];
    			var myLatLng = new google.maps.LatLng(location[1], location[2]);
    			var marker = new google.maps.Marker( {
    				position : myLatLng,
    				map : map,
    				icon : image,
    				shape : shape,
    				title : location[0],
    				zIndex : location[3]
    			});
    			//alert( marker[i].getTitle());
    			google.maps.event.addListener(marker, 'click', function() {
    			    Solar.openInfoWindow(marker);
    			  });
    		}
    Where Solar is the namespace for my functions
    It throws no errors, however all the time only the last marker item is passed to Solar.openInfoWindow. How come?

    Regards, Geert

  2. #2
    Join Date
    Jan 2011
    Posts
    2
    I already know the answer. (Because you guys waited 6 hours before posting this message, consider some European moderators maybe...)

    You can make use of the this namespace, which is a reference to the calling object

    Or (more durable) you can wrap it up into another function, and have marker declared there, and then into the calling function.

    Regards, Geert

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles