Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disono/f2882f17b36cc0434cf7aab3dd6d852b to your computer and use it in GitHub Desktop.
Save disono/f2882f17b36cc0434cf7aab3dd6d852b to your computer and use it in GitHub Desktop.

Coordinates

<?php
/**
 * Author: Archie, Disono (disono.apd@gmail.com)
 */

namespace App\Models;

class Route
{
  /**
  * Distance
  * Returns the distance in kilometers, assuming earth radius of 6,371 km.
  *
  * @param $lat
  * @param $lng
  *
  * @return string
  */
  private static function distanceStart($lat, $lng)
  {
      return '6371 * 2 * ASIN(SQRT(POWER(SIN((' . $lat .
          ' - ABS(table_name.lat)) * PI() / 180 / 2), 2) + COS(' . $lat .
          ' * PI() / 180) * COS(ABS(table_name.lat) * PI() / 180) * POWER(SIN((' . $lng .
          ' - table_name.lng) * PI() / 180 / 2), 2)))';
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment