function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David Zhu 8David Zhu 8 

Google Map multiple markers Click Event always opening the last case

Hi all,
I have a VF page displaying google map.
I want to archive two goals:
1. displaying case locations on the map.
2.when click marker on the map, the related case will be open.

I don't have any issue to display those locations on the map.The problem is when clicking any marker, it always opens the last case in both Console or non console application.
Can someone help me out?



Thanks,
David
 
for (var i = 0; i < locations.length; i++) 
{
    try
    {
        var icn = "/resource/Img/reddot.png";
       	
						    	
        var marker = new google.maps.Marker({
                title: locations[i].title,
                position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
                icon: icn,
                url: locations[i].url,
                map: map
            });

        google.maps.event.addListener(marker, 'click', function () {
        if(isConsole)
            sforce.console.openPrimaryTab(null,marker.url,true,marker.casenumber,function(result){},marker.casenumber);
        else
            window.open( marker.url,'_blank');
        });
			
    }
    catch(err){}
}

 
David Zhu 8David Zhu 8
I found the fix for the code. "THIS" does the trick.
 
for (var i = 0; i < locations.length; i++) 
{
    try
    {
        var icn = "/resource/Img/reddot.png";
       	
						    	
        var marker = new google.maps.Marker({
                title: locations[i].title,
                position: new google.maps.LatLng(locations[i].lat, locations[i].lng),
                icon: icn,
                url: locations[i].url,
                map: map
            });

        google.maps.event.addListener(marker, 'click', function () {
        if(isConsole)
            sforce.console.openPrimaryTab(null,this.url,true,this.casenumber,function(result){},this.casenumber);
        else
            window.open( this.url,'_blank');
        });
			
    }
    catch(err){}
}