PHPackages                             omelya/phpgeo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. omelya/phpgeo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

omelya/phpgeo
=============

Simple Yet Powerful Geo Library

v1.0.0(2y ago)02.7k↓33.3%MITPHPPHP ^7.3 || ^8.0 || ^8.1

Since Aug 18Pushed 2y agoCompare

[ Source](https://github.com/Omelya/phpgeo)[ Packagist](https://packagist.org/packages/omelya/phpgeo)[ Docs](https://phpgeo.marcusjaschen.de/)[ Fund](https://www.paypal.com/paypalme/mjaschen)[ GitHub Sponsors](https://github.com/mjaschen)[ RSS](/packages/omelya-phpgeo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

phpgeo - A Simple Geo Library for PHP
=====================================

[](#phpgeo---a-simple-geo-library-for-php)

phpgeo provides abstractions to geographical coordinates (including support for different ellipsoids) and allows you to calculate geographical distances between coordinates with high precision.

[![Latest Stable Version](https://camo.githubusercontent.com/7bcdfa16796c03c464441f35b15d1ef05ee4cfbe042976ecdefbb8a3abd6d703/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f70687067656f2f76)](//packagist.org/packages/mjaschen/phpgeo)[![Total Downloads](https://camo.githubusercontent.com/391b2024ce87e16b960ea2640d65975fdc804586bae9612579978b5d8e40ba6c/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f70687067656f2f646f776e6c6f616473)](//packagist.org/packages/mjaschen/phpgeo)[![phpgeo Tests](https://github.com/mjaschen/phpgeo/actions/workflows/php.yml/badge.svg)](https://github.com/mjaschen/phpgeo/actions/workflows/php.yml)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9e761844b3fef919244941c0392f2be4a1703aa2919588ca17bb4cbb173e3efb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a61736368656e2f70687067656f2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mjaschen/phpgeo/?branch=master)[![License](https://camo.githubusercontent.com/8de3df1a6f808eec97fc5cd4fa0d7f02970add207f28bd094809d56c1a35ec14/68747470733a2f2f706f7365722e707567782e6f72672f6d6a61736368656e2f70687067656f2f6c6963656e7365)](//packagist.org/packages/mjaschen/phpgeo)

Table of Contents
-----------------

[](#table-of-contents)

- [phpgeo - A Simple Geo Library for PHP](#phpgeo---a-simple-geo-library-for-php)
    - [Table of Contents](#table-of-contents)
    - [Requirements](#requirements)
    - [Documentation](#documentation)
    - [Installation](#installation)
    - [Upgrading](#upgrading)
    - [License](#license)
    - [Features](#features)
    - [Examples/Usage](#examplesusage)
        - [Distance between two coordinates (Vincenty's Formula)](#distance-between-two-coordinates-vincentys-formula)
        - [Simplifying a polyline](#simplifying-a-polyline)
        - [Polygon contains a point (e.g. "GPS geofence")](#polygon-contains-a-point-eg-gps-geofence)
        - [Formatted output of coordinates](#formatted-output-of-coordinates)
            - [Decimal Degrees](#decimal-degrees)
            - [Degrees/Minutes/Seconds (DMS)](#degreesminutesseconds-dms)
            - [GeoJSON](#geojson)
    - [Development](#development)
        - [Run Tests](#run-tests)
        - [Running GitHub Actions locally](#running-github-actions-locally)
    - [Credits](#credits)

Requirements
------------

[](#requirements)

Minimum required PHP version is 7.3. *phpgeo* fully supports PHP 8 and is tested up to PHP 8.2.

The 3.x releases require PHP &gt;= 7.2 but don't get feature updates any longer. Bugfixes will be backported.

The 2.x releases require PHP &gt;= 7.0 but don't get feature updates any longer. Bugfixes won't be backported.

The 1.x release line has support for PHP &gt;= 5.4. Bugfixes won't be backported.

Documentation
-------------

[](#documentation)

The documentation is available at

Installation
------------

[](#installation)

Using [Composer](https://getcomposer.org), just add it to your `composer.json` by running:

```
composer require mjaschen/phpgeo

```

Upgrading
---------

[](#upgrading)

Update the version constraint in the project's `composer.json` and run `composer update` or require the new version by running:

```
composer require mjaschen/phpgeo:^4.0
```

License
-------

[](#license)

Starting with version 2.0.0 phpgeo is licensed under the MIT license. Older versions were GPL-licensed.

Features
--------

[](#features)

**Info:** Please visit the **[documentation site](https://phpgeo.marcusjaschen.de/)** for complete and up-to-date documentation with many examples!

phpgeo provides the following features (follow the links for examples):

- abstractions of several geometry objects ([coordinate/point](https://phpgeo.marcusjaschen.de/Geometries/Coordinate.html), [line](https://phpgeo.marcusjaschen.de/Geometries/Line.html), [polyline/GPS track](https://phpgeo.marcusjaschen.de/Geometries/Polyline.html), [polygon](https://phpgeo.marcusjaschen.de/Geometries/Polygon.html)
- support for different [ellipsoids](https://phpgeo.marcusjaschen.de/Geometries/Ellipsoid.html), e.g. WGS-84
- [length/distance/perimeter calculations](https://phpgeo.marcusjaschen.de/Calculations/Distance_and_Length.html)with different implementations (Haversine, Vincenty)
- [Geofence](https://phpgeo.marcusjaschen.de/Calculations/Geofence.html) calculation, i.e. answering the question "Is this point contained in that area/polygon?" and other [intersection](https://phpgeo.marcusjaschen.de/Comparisons/Intersections.html) checks between different geometries
- [formatting and output](https://phpgeo.marcusjaschen.de/Formatting_and_Output/index.html) of geometry objects (GeoJSON, nice strings, e. g. `18° 54′ 41″ -155° 40′ 42″`)
- calculation of [bearing angle between two points](https://phpgeo.marcusjaschen.de/Calculations/Bearing_and_Destination.html#page_Bearing-between-two-points)(spherical or with Vincenty's formula)
- calculation of a [destination point for a given starting point](https://phpgeo.marcusjaschen.de/Calculations/Bearing_and_Destination.html#page_Destination-point-for-given-bearing-and-distance), bearing angle, and distance (spherical or with Vincenty's formula)
- calculation of the [perpendicular distance between a point and a line](https://phpgeo.marcusjaschen.de/Calculations/Perpendicular_Distance.html)
- calculation of the [Cardinal Distances between two points](https://phpgeo.marcusjaschen.de/Calculations/Cardinal_Distance.html)
- getting segments of a [polyline](https://phpgeo.marcusjaschen.de/Geometries/Polyline.html#page_Segments)/[polygon](https://phpgeo.marcusjaschen.de/Geometries/Polygon.html#page_Segments),
- [reversing direction](https://phpgeo.marcusjaschen.de/Geometries/Polygon.html#page_Reverse-Direction)of polyline/polygon

Examples/Usage
--------------

[](#examplesusage)

This list is incomplete, please visit the [documentation site](https://phpgeo.marcusjaschen.de/)for the full monty of documentation and examples!

### Distance between two coordinates (Vincenty's Formula)

[](#distance-between-two-coordinates-vincentys-formula)

Use the calculator object directly:

```
