All Projects → mjaschen → Phpgeo

mjaschen / Phpgeo

Licence: mit
Simple Yet Powerful Geo Library for PHP

Projects that are alternatives of or similar to Phpgeo

gpx-builder
Builder of GPX files
Stars: ✭ 25 (-98.09%)
Mutual labels:  gps, location
Location
Smartphone navigation positionning, fusion GPS and IMU sensors.
Stars: ✭ 87 (-93.34%)
Mutual labels:  gps, location
roam-reactnative
React Native Location SDK. High accuracy and battery efficient location SDK for iOS and Android by Roam.ai
Stars: ✭ 20 (-98.47%)
Mutual labels:  gps, location
surger
⚡ Is there surge pricing around me right now?
Stars: ✭ 20 (-98.47%)
Mutual labels:  gps, location
EasyWayLocation
This library contain all utils related to google location. like, getting lat or long, Address and Location Setting dialog, many more...
Stars: ✭ 142 (-89.13%)
Mutual labels:  gps, location
orange3-geo
🍊 🌍 Orange add-on for dealing with geography and geo-location
Stars: ✭ 22 (-98.32%)
Mutual labels:  gps, location
Indoorgps
Position Calculating with Trilateration via Bluetooth Beacons(Estimote)
Stars: ✭ 59 (-95.48%)
Mutual labels:  gps, location
Maps
🌍🌏🌎 The whole world fits inside your cloud!
Stars: ✭ 253 (-80.63%)
Mutual labels:  gps, location
android-amap-track-collect
这阵子由于项目需要,需要从手机上采集用户的运动轨迹数据,这样的功能大家都见到的很多了,比如咕咚、悦动圈,对跑步运动轨迹数据进行采集,再如,微信运动、钉钉运动,对于每一天你走步进行计数,如果要记录轨迹就离不开的手机定位,如果要记录步数那就离不开陀螺仪(角速度传感器),花了一天多的时间实现了一个定位数据实时采集的功能。
Stars: ✭ 50 (-96.17%)
Mutual labels:  gps, location
react-native-device-country
Get device location by telephony (SIM card) or settings without using GPS tracker.
Stars: ✭ 33 (-97.47%)
Mutual labels:  gps, location
Atlas
🌎 Atlas is a set of APIs for looking up information about locations
Stars: ✭ 21 (-98.39%)
Mutual labels:  gps, location
Leaflet Gps
Simple leaflet control plugin for tracking gps position
Stars: ✭ 90 (-93.11%)
Mutual labels:  gps, location
LocationShare
A simple Android application to share your location
Stars: ✭ 75 (-94.26%)
Mutual labels:  gps, location
aic-mobile-ios
Art Institute of Chicago Official Mobile App
Stars: ✭ 29 (-97.78%)
Mutual labels:  gps, location
FusedBulb
Location fetch library.
Stars: ✭ 22 (-98.32%)
Mutual labels:  gps, location
gps-share
Utility to share your GPS device on local network
Stars: ✭ 49 (-96.25%)
Mutual labels:  gps, location
Ulogger Android
μlogger • android application for real-time collection and publishing of geolocation data
Stars: ✭ 168 (-87.14%)
Mutual labels:  gps, location
Geolocation
Flutter geolocation plugin for Android and iOS.
Stars: ✭ 205 (-84.3%)
Mutual labels:  gps, location
telegram-nearby-map
Discover the location of nearby Telegram users 📡🌍
Stars: ✭ 329 (-74.81%)
Mutual labels:  gps, location
Rxgps
Finding current location cannot be easier on Android !
Stars: ✭ 307 (-76.49%)
Mutual labels:  gps, location

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 Total Downloads phpgeo Tests Scrutinizer Code Quality License

Table of Contents

Requirements

Minimum required PHP version is 7.2. phpgeo fully supports PHP 8.0.

The 2.x releases require PHP >= 7.0 but don't get feature updates any longer. Bugfixes will be backported.

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

Documentation

The documentation is available at https://phpgeo.marcusjaschen.de/

API documentation is available as well: https://phpgeo.marcusjaschen.de/api/

Installation

Using Composer, just add it to your composer.json by running:

composer require mjaschen/phpgeo

License

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

Features

Info: Please visit the documentation site for complete and up-to-date documentation with many examples!

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

Examples/Usage

This list is incomplete, please visit the documentation site for the full monty of documentation and examples!

Distance between two coordinates (Vincenty's Formula)

Use the calculator object directly:

<?php

use Location\Coordinate;
use Location\Distance\Vincenty;

$coordinate1 = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit
$coordinate2 = new Coordinate(20.709722, -156.253333); // Haleakala Summit

$calculator = new Vincenty();

echo $calculator->getDistance($coordinate1, $coordinate2); // returns 128130.850 (meters; ≈128 kilometers)

or call the getDistance() method of a Coordinate object by injecting a calculator object:

<?php

use Location\Coordinate;
use Location\Distance\Vincenty;

$coordinate1 = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit
$coordinate2 = new Coordinate(20.709722, -156.253333); // Haleakala Summit

echo $coordinate1->getDistance($coordinate2, new Vincenty()); // returns 128130.850 (meters; ≈128 kilometers)

Simplifying a polyline

Polylines can be simplified to save storage space or bandwidth. Simplification is done with the Ramer–Douglas–Peucker algorithm (AKA Douglas-Peucker algorithm).

<?php

use Location\Coordinate;
use Location\Polyline;
use Location\Distance\Vincenty;

$polyline = new Polyline();
$polyline->addPoint(new Coordinate(10.0, 10.0));
$polyline->addPoint(new Coordinate(20.0, 20.0));
$polyline->addPoint(new Coordinate(30.0, 10.0));

$processor = new Simplify($polyline);

// remove all points which perpendicular distance is less
// than 1500 km from the surrounding points.
$simplified = $processor->simplify(1500000);

// simplified is the polyline without the second point (which
// perpendicular distance is ~1046 km and therefore below
// the simplification threshold)

Polygon contains a point (e.g. "GPS geofence")

phpgeo has a polygon implementation which can be used to determinate if a point is contained in it or not. A polygon consists of at least three points. Points are instances of the Coordinate class.

Warning: The calculation gives wrong results if the polygons has points on both sides of the 180/-180 degrees meridian.

<?php

use Location\Coordinate;
use Location\Polygon;

$geofence = new Polygon();

$geofence->addPoint(new Coordinate(-12.085870,-77.016261));
$geofence->addPoint(new Coordinate(-12.086373,-77.033813));
$geofence->addPoint(new Coordinate(-12.102823,-77.030938));
$geofence->addPoint(new Coordinate(-12.098669,-77.006476));

$outsidePoint = new Coordinate(-12.075452, -76.985079);
$insidePoint = new Coordinate(-12.092542, -77.021540);

var_dump($geofence->contains($outsidePoint)); // returns bool(false) the point is outside the polygon
var_dump($geofence->contains($insidePoint)); // returns bool(true) the point is inside the polygon

Formatted output of coordinates

You can format a coordinate in different styles.

Decimal Degrees

<?php

use Location\Coordinate;
use Location\Formatter\Coordinate\DecimalDegrees;

$coordinate = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit

echo $coordinate->format(new DecimalDegrees());

Degrees/Minutes/Seconds (DMS)

<?php

use Location\Coordinate;
use Location\Formatter\Coordinate\DMS;

$coordinate = new Coordinate(18.911306, -155.678268); // South Point, HI, USA

$formatter = new DMS();

echo $coordinate->format($formatter); // 18° 54′ 41″ -155° 40′ 42″

$formatter->setSeparator(", ")
    ->useCardinalLetters(true)
    ->setUnits(DMS::UNITS_ASCII);

echo $coordinate->format($formatter); // 18° 54' 41" N, 155° 40' 42" W

GeoJSON

<?php

use Location\Coordinate;
use Location\Formatter\Coordinate\GeoJSON;

$coordinate = new Coordinate(18.911306, -155.678268); // South Point, HI, USA

echo $coordinate->format(new GeoJSON()); // { "type" : "point" , "coordinates" : [ -155.678268, 18.911306 ] }

Development

Run Tests

Before submitting a pull request, please be sure to run all checks and tests and ensure everything is green.

  • lint PHP files for syntax errors: composer ci:lint
  • run static analysis with Psalm and report errors: composer ci:psalm
  • run unit tests with PHPUnit: composer ci:tests

To run all checks and tests at once, just use composer ci.

Of course, it's possible to use the test runners directly, e.g. for PHPUnit:

./vendor/bin/phpunit

Psalm:

./vendor/bin/psalm

Miscellaneous

@clemdesign created a TypeScript port of phpgeo.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].