title: Geospatial distance calculator using Sequelize & MySQL
body: <p>I have a Location model in Sequelize</p>
  
  <pre><code>var Sequelize = require('sequelize');
  
  module.exports = function(sequelize, DataTypes) {
     var Location = sequelize.define('Location', {
        location_id: {
           type: Sequelize.STRING,
           primaryKey: true
        },
        location_code: {
           type: Sequelize.STRING,
           allowNull: true
        },
        location_name: {
           type: Sequelize.STRING,
           allowNull: true
        },
        latitude: {
           type: Sequelize.STRING,
           allowNull: true,
           defaultValue: null
        },
        longitude: {
           type: Sequelize.STRING,
           allowNull: true,
           defaultValue: null
        },
        location: {
           type: Sequelize.GEOMETRY('POINT'),
           allowNull: true
        }
     });
     return Location;
  };
  </code></pre>
  
  <p>I insert latitude and longitude into location by feeding it</p>
  
  <pre><code>var location = { type: 'Point', coordinates: [latitude, longitude] };
  </code></pre>
  
  <p>I have a router which gets latitude and longitude as parameters. I need to find out the distance between the provided lat/long and all the locations in the Locations table.</p>
  
  <p>How can I go about doing it? Does Sequelize already provide me with a function to find out the distance or do I need to write an external query to find it?</p>
  
  <p>Thanks.  </p>