title: Draw Polylines and Polygons based on MongoDB stored GeoJson Coordinates
body: <p>I'm realizing an application which is supposed to show on a Google Map <code>Points</code>, <code>LineStrings</code> and <code>Polygons</code>.</p>
  
  <p>I'm using a <code>Mongoose</code> schema which allows those 3 kind of data to get stored and I'm able to post all of them with no problems.</p>
  
  <p>I'm already able to draw <code>Points</code> since they have only 1 entry per <code>lat, lng</code> pair, but, I'm really struggling with understanding how to fetch <code>LineString</code> and <code>Polygon</code> <code>lat, lng</code> couples from the db, store them in a matrix and then drawing these object into the map.</p>
  
  <p>This is what I'm trying to do for <strong>LineStrings</strong>:</p>
  
  <pre><code>var valueToPush = [];
  
  // Loop through all of the JSON entries provided in the response
  for (var i = 0; i &lt; response.length; i++) {
      var user = response[i];
  
        if (user.location.type === "LineString") {
  
           for (var j = 0; j &lt; user.location.coordinates.length; j++) {
  
               valueToPush[j] = user.location.coordinates[j];
               valueToPush[j+1] = user.location.coordinates[j+1];
            }
         }
  
     return valueToPush;
  };
  
  console.log(valueToPush); //Printing the right LineString Points
  </code></pre>
  
  <p>And this is how I'm trying to draw <strong>LineStrings</strong>:</p>
  
  <pre><code>var initialize = function() {
  
    valueToPush.forEach(function(){
       var myPath = new google.maps.Polyline({
                    path: parseFloat(valueToPush),
                    geodesic: true,
                    strokeColor: '#FF0000',
                    strokeOpacity: 1.0,
                    strokeWeight: 2
        });
  
        myPath.setMap(map);
    });
  }
  </code></pre>
  
  <p>But from the latter i get <code>InvalidValueError: not an Array js?key=myKey</code></p>
  
  <p>This is my <strong>Mongoose Schema</strong>:</p>
  
  <pre><code>// Pulls Mongoose dependency for creating schemas
  var mongoose = require('mongoose');
  var GeoJSON  = require('geojson');
  var Schema   = mongoose.Schema;
  
  var LocationSchema = new Schema({
                                      name: {type: String, required: true},
                                      location: {
                                        type: {type : String, required: true},
                                        coordinates : [Schema.Types.Mixed]
                                      },
                                      created_at: {type: Date, default: Date.now},
                                      updated_at: {type: Date, default: Date.now}
  });
  
  // Sets the created_at parameter equal to the current time
  LocationSchema.pre('save', function(next){
      now = new Date();
      this.updated_at = now;
      if(!this.created_at) {
          this.created_at = now
      }
      next();
  });
  
  // Indexes this schema in 2dsphere format (critical for running proximity searches)
  LocationSchema.index({location: '2dsphere'});
  
  module.exports = mongoose.model('mean-locations', LocationSchema);
  </code></pre>
  
  <p>And this is how I post a new LineString using <strong>Postman</strong>:</p>
  
  <pre><code>{
    "name": "FirstPolyline",
    "location": {
                              "type":"LineString",
                              "coordinates": 
                                              [ [100.0, 0.0], [101.0, 0.0] ]
  
    }
  }
  </code></pre>
  
  <p><strong>What Am I doing wrong? How Can I fix this?</strong></p>
  
  <p>Thanks in Advance.</p>