set polylines in googlemap from values in PHP
<p>I have seen this link:</p>

<p><a href="http://stackoverflow.com/questions/8176349/google-map-api-v3-add-polylines-from-array">Google map api v3 add polylines from array</a></p>

<p>this is somehow slightly the same as my problem.. you see, im getting a javscript error as such this:</p>

<pre><code>Uncaught TypeError: Cannot call method 'getPath' of undefined 
AddCoordinate map:118
(anonymous function)
</code></pre>

<p>well my code is basically populating the coordinates first as the page is loaded together with the map.. And by the time that click is triggered (html button), that is the only time that the map will be plotted with poly lines.. I hope I explained it very well though.. Here's what i got:</p>

<pre><code>    var map;
    var Markers = [];
    var Coordinates = [];
    var LinePath;

    function initialize()
    {  
      var myLatLng = new google.maps.LatLng(21.291982, -140.821856);
      var myOptions = {
                zoom: 3,
            center: myLatLng,
            mapTypeId: google.maps.MapTypeId.SATELLITE
          };
      var MarkerSize = new google.maps.Size(48,48);
      map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }

    function AddCoordinate( lat, long )                                                                                                                         {
      var path = LinePath.getPath(); 
      path.push( new google.maps.LatLng( lat, long ) );
      LinePath.setPath(path);
    }


    function PlotLine()
    {
      LinePath = new google.maps.Polyline({
                path:Coordinates,                                                                                                                           
                strokeColor:"#ffffff",
                strokeOpacity:1.0,
                strokeWeight:5
                });
      LinePath.setMap(map);
    }


   &lt;html&gt;
    &lt;body onload="initialize()"&gt;
    &lt;div id="map_canvas" &gt;&lt;/div&gt;
    &lt;?php
                    foreach($arrayOfPlotPoints as $key =&gt; $value){ 
                        $longitude = round($value['longitude'],5);
                        $latitude = round($value['latitude'],5);
                        $snrLevel = $value['snr_level'];
                        echo '&lt;script type="text/javascript"&gt;AddCoordinate('.$latitude.','.$longitude.')&lt;/script&gt;';
                    ?&gt;
                        &lt;option value="&lt;?php echo $longitude.",".$latitude.",".$snrLevel?&gt;"&gt; Lg:&lt;?php echo $longitude." Lt: ".$latitude." LV: ".$snrLevel?&gt;&lt;/option&gt;
                        &lt;?php } ?&gt;
                    &lt;/select&gt;
                    &lt;br /&gt;&lt;br /&gt;
                    &lt;?php echo $this-&gt;Form-&gt;button('PLOT', array('type'=&gt;'button', 'onclick'=&gt;'PlotLine()')); ?&gt;
echo $this-&gt;Form-&gt;button('PLOT', array('type'=&gt;'button', 'onclick'=&gt;'PlotLine()')); 
     ?&gt;
</code></pre>

<p><em><strong></em>*</strong><em>EDITED</em><strong><em>*</em>**</strong></p>

<p>i have made a partial modification of my code.. however im getting the same error.. </p>

<pre><code>Uncaught TypeError: Cannot call method 'getPath' of undefined 
    AddCoordinate (anonymous function)


function initialize() {
 //.....
 LinePath = new google.maps.Polyline({
        path:Coordinates,                                                                                                                           //san ka galing Coordinates??? dineclare ka pero di ka aman nilagyan "YATA" ng laman
        strokeColor:"#ffffff",
        strokeOpacity:1.0,
        strokeWeight:5
        });
}


function AddCoordinate( latitude, longitude )                                                                                                                       {
  var path = LinePath.getPath(); 
  path.push(  latitude, longitude  );
}

function PlotLine()
{
  LinePath = new google.maps.Polyline({
            path:Coordinates,                                                                                                                           
            strokeColor:"#ffffff",
            strokeOpacity:1.0,
            strokeWeight:5
            });
  LinePath.setMap(map);

}

&lt;HTML&gt;
select name="long_and_lat" id="long_and_lat" style="width:220px;height:250px;" size="100"&gt;
                &lt;?php    
                $plotPoints = array();
                foreach($arrayOfPlotPoints as $key =&gt; $value){ 
                    $longitude = round($value['longitude'],5);
                    $latitude = round($value['latitude'],5);
                    $snrLevel = $value['snr_level'];
                    echo '&lt;script type="text/javascript"&gt;AddCoordinate('.$latitude.','.$longitude.')&lt;/script&gt;';
                ?&gt;
                    &lt;option value="&lt;?php echo $longitude.",".$latitude.",".$snrLevel?&gt;"&gt; Lg:&lt;?php echo $longitude." Lt: ".$latitude." LV: ".$snrLevel?&gt;&lt;/option&gt;
                    &lt;?php } ?&gt;
                &lt;/select&gt;
                &lt;br /&gt;&lt;br /&gt;
                &lt;?php echo $this-&gt;Form-&gt;button('PLOT', array('type'=&gt;'button', 'onclick'=&gt;'PlotLine()')); ?&gt;
&lt;/html&gt;
</code></pre>
