Adding click event to markers

552 views
Skip to first unread message

Autive bedrijf

unread,
Nov 2, 2011, 10:48:45 AM11/2/11
to google-map...@googlegroups.com
Hi there,

Im pretty new to the maps api, but after finding out to get my markers just as i want them i came to an problem i cant fix.

I for the following code for my markers:


function initialize() {
            var latlng = new google.maps.LatLng(53.033117,5.639752);
            var latingSiton = new google.maps.LatLng(53.0356197730161,5.62613738302669);
            var SitonImg = 'images/siton.png';
            var latingZee = new google.maps.LatLng(53.0360534900284,5.62488617774811);
            var ZeeImg = 'images/zee.png';
            var latingHylkema = new google.maps.LatLng(53.0373853769166,5.62924255777811);
            var HylkemaImg = 'images/hylkema.png';
            var latingDijkstra = new google.maps.LatLng(53.0360125088934,5.62735529113307);
            var DijkstraImg = 'images/dijkstra.png';
           
            var myOptions = {
              zoom: 16,
              center: latlng,
              mapTypeId: google.maps.MapTypeId.ROADMAP
            };
           
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
              var marker = new google.maps.Marker({
                  position: latingSiton,
                  map: map,
                  title:"Hello World!",
                  icon: SitonImg,
              })
              var marker = new google.maps.Marker({
                  position: latingZee,
                  map: map,
                  title:"Hello World!",
                  icon: ZeeImg,
              })
              var marker = new google.maps.Marker({
                  position: latingHylkema,
                  map: map,
                  title:"Hello World!",
                  icon: HylkemaImg,
              })
              var marker = new google.maps.Marker({
                  position: latingDijkstra,
                  map: map,
                  title:"Hello World!",
                  icon: DijkstraImg,
              })
              }

But now I would like to activate an javascript event when the marker is clicked for example:

$('.toggler').live('click',function(){
                  $(this).parent().children().toggle();  //swaps the display:none between the two spans
            
              }); 

Is this possible for making the marker do such things when it is clicked?

Masashi.K

unread,
Nov 2, 2011, 6:54:40 PM11/2/11
to Google Maps JavaScript API v3
Hi.

Do you want to change clickable attribute of marker, don't you?

If so, you can change via Marker.setClickable() method.
Here is an example.
http://googlemaps.googlermania.com/google_maps_api_v3/map_example_click_change.html

Rossko

unread,
Nov 2, 2011, 10:13:27 PM11/2/11
to Google Maps JavaScript API v3
> But now I would like to activate an javascript event when the marker is
> clicked for example:

Add event listeners to yoiur markers, and have them run whatever code
you want
Example
http://code.google.com/apis/maps/documentation/javascript/events.html#EventClosures
Reply all
Reply to author
Forward
0 new messages