title: LatLng as an exploded array in Google Maps API
body: <p>I'm retrieving a string of LatLng coordinates from a database and used PHP's explode function and stored it in an array. I want to pass the array from PHP to JavaScript. Also, I want the Polygon function to accept the array and draw the coordinates accordingly. I'm currently stumped. :( Please help.</p>
  
  <pre><code>&lt;script type="text/javascript"
              src="https://maps.googleapis.com/maps/api/js?key=AIzZfro&amp;sensor=false"&gt;
  &lt;/script&gt;
  &lt;script&gt;
      function initialize() {
          var myLatLng = new google.maps.LatLng(8.5000,125.8333);
          var myOptions = {
              zoom: 8,
              center: myLatLng,
          };
  
          var map = new google.maps.Map(document.getElementById("map-canvas"),
             myOptions);
          var davaoCoordinates = [
              new google.maps.LatLng(7.0644,125.6078),
              new google.maps.LatLng(8.4833,124.6500),
              new google.maps.LatLng(8.5000,125.8333)
          ];
  
          var davaoCity = new google.maps.Polygon({
              path: davaoCoordinates,
              strokeColor: "#FF0000",
              strokeOpacity: 1.0,
              strokeWeight: 2
           });
  
          davaoCity.setMap(map);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
  &lt;/script&gt;
  </code></pre>
  
  <p>Here's the PHP code:</p>
  
  <pre><code>&lt;?php
  $connect = mysql_connect("localhost", "root", "");
  mysql_select_db('capdb');
  
  if (mysqli_connect_errno()){
      echo "Failed to connect to database: " . mysqli_connect_error();
  }
  
  $query ="SELECT cap_info.event, cap_info.sendername, cap_info.urgency, cap_area.polygon
      FROM cap_info
      INNER JOIN cap_area ON cap_info.capid = cap_area.capid
      WHERE cap_info.capid =1";
  $result = mysql_query($query);
  
  if (!$result){
      echo "Query Error." . mysql_error();
      exit;
  }
  
  if (mysql_num_rows($result) == 0){
      echo "No rows found, nothing to print.";
      exit;
  }
  while ($row = mysql_fetch_array($result)){
      $event = $row['event'];
      $sender = $row['sendername'];
      $urgency = $row['urgency'];
      $polygon = $row['polygon']."\n";
  }
  $coordsArray = explode (" ", $polygon);
  $count = sizeof($coordsArray);
  //$n=0;
  //while ($n &lt; $count){
  //echo $coordsArray[$n];
  //$n++;
  //}
  ?&gt;
  </code></pre>