Skip to content

roslov/location

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Location Calculator

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

This package provides calculations based on longitude and latitude.

Features

It calculates distance between two locations.

It uses the “haversine” formula to calculate the great-circle distance between two points — that is, the shortest distance over the earth’s surface — giving an “as-the-crow-flies” distance between the points.

Formula:

a = sin²( Δφ / 2 ) + cos φ1 × cos φ2 × sin²( Δλ / 2 )
c = 2 × atan2( √a, √( 1 − a ) )
d = R × c

where φ is latitude, λ is longitude, R is the earth’s radius (mean radius = 6371 km).

Requirements

  • PHP 7.2 or higher.

Installation

The package could be installed with composer:

composer require roslov/location

General usage

Validator allows to check data in any format. For example, when data is an object:

use Roslov\Location\LocationCalculator;

$locationCalculator = new LocationCalculator();
$distance = $locationCalculator->getDistance(49.841905, 24.031511, 50.450885, 30.522798);
echo $distance; // 467.32327173219

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages