how could i save value from loop for event,
            for (var i = 0, len = features.length; i < len; i++) {
                    if (features[i].type == 'tower')
                    {
                        for (var j = 0; j < markers.length; j++) {
                            var lines = [];
                            lines.push(features[i].position);
                            lines.push(markers[j].position);
                            var connectionPath = new google.maps.Polyline({
                                path: lines,
                                geodesic: true,
                                strokeColor: '#12aab5',
                                strokeOpacity: 0.8,
                                strokeWeight: 3
                            });
                            connectionPaths.push(connectionPath);
                            connectionPath.setMap(map);
                            connectionPath.addListener('click', function() {
                                var elevator = new google.maps.ElevationService();
                                displayPathElevation(getPathVariableCode(connectionPath), elevator, map,  features[i], markers[j]);
                            });
                        }
                    }
                }
features[i], markers[j] are null.
probably because they are called after i and j are already irrelevant .
i looking to use features[i] and markers[j] on the click event .
how could i preform something like this?
 
     
     
    