Skip to content

Instantly share code, notes, and snippets.

View guangrei's full-sized avatar
💭
I may be slow to respond.

Am K guangrei

💭
I may be slow to respond.
View GitHub Profile
@guangrei
guangrei / distanceCalculation.php
Created July 10, 2018 10:19 — forked from nirendra/distanceCalculation.php
Calculate distance between two points
The function below use the latitude and longitude of two locations, and calculate the distance between them in both miles and metric units.
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
$feet = $miles * 5280;
$yards = $feet / 3;