title: Sequelize geospatial query: find "n" closest points to a location
body: <p>Using <a href="https://github.com/sequelize/sequelize" rel="noreferrer">Sequelize</a> and geospatial queries, if I want to find the "n" closest points to a certain location, how should the Sequelize query be?</p>
  
  <p>Assume I have a model that looks something like this:</p>
  
  <pre><code>sequelize.define('Point', {geo: DataTypes.GEOMETRY('POINT')});
  </code></pre>
  
  <p>Now let's say we input 100 random points in the db through something like:</p>
  
  <pre><code>db.Point.create({geo: {type: 'Point', coordinates: [randomLng,randomLat]}});
  </code></pre>
  
  <p>Imagine we have a <code>lat</code> and <code>lng</code> variables to define a location, and we want to find the 10 closest points to it. when I run this query I get an error:</p>
  
  <pre><code>const location = sequelize.literal(`ST_GeomFromText('POINT(${lat} ${lng})', 4326)`);
  
  db.Point.findAll({
    attributes: [['distance', sequelize.fn('ST_Distance', sequelize.col('Point'), location)]],
    order: 'distance',
    limit: 10
  });
  
  // -&gt; TypeError: s.replace is not a function
  </code></pre>
  
  <p>Any idea what is the issue / how to fix it?</p>
  
  <p>Thx!</p>