Skip to content

simple geolocation library wrapping league/geotools

License

Notifications You must be signed in to change notification settings

bakame-php/geolocation

Repository files navigation

Get information on a position

This package uses geolocation to determine several properties around the sun position.

This package is a fork of Spatie/Sun

Installation

You can install the package via composer:

composer require bakame-php/geolocation

Usage

To instantiate the Bakame\Geolocation\Geolocation class you need to use one of the following named constructor.

use Bakame\Geolocation\Geolocation;

//Brussels coordinates and GeoHash
$bxLatitude = 50.85045;
$bxLongitude = 4.3487805;
$bxGeohash = 'u1516cn9mfvv';

$location = GeoLocation::fromCoordinates($bxLatitude, $bxLongitude);
$location = Geolocation::fromGeoHash($bxGeohash);

On failed instantiation a Bakame\Geolocation\CanNotGenerateGeolocation exception is thrown.

  • Latitudes below -90.0 or above 90.0 degrees are capped, not wrapped.
  • Longitudes below -180.0 or above 180.0 degrees are wrapped.

Because the package is using the Geotools library, you can use other coordinates representation to instantiate a new object.

use Bakame\Geolocation\Geolocation;
use League\Geotools\Coordinate\Coordinate;

$bxDegrees = '50°51\'1.62"N, 4°20\'55.61"E';
$geoCoordinate = new Coordinate($bxDegrees);
$location = GeoLocation::fromGeotools($geoCoordinate);

Get the time of zenith

You can get the time of the zenith.

$location->zenith(); // returns an instance of \DateTimeImmutable

You can get the time of the zenith on a specific date by passing an object which implements DateTimeInterface to zenith

If the object extends DateTimeImmutable the return object will be of the same type.

$carbon = CarbonImmutable::now();
$location->zenith($carbon); // returns an instance of \Carbon\CarbonImmutable

Get the time of sunrise

You can get the time of the sunrise.

$location->sunrise(); // returns an instance of \DateTimeImmutable

You can get the time of the sunrise on a specific date by passing an object which implements DateTimeInterface to sunrise

If the object extends DateTimeImmutable the return object will be of the same type.

$carbon = CarbonImmutable::now();
$location->sunrise($carbon); // returns an instance of \Carbon\CarbonImmutable

If no sunrise information is available for a specific geolocation null is returned.

Get the time of sunset

You can get the time of the sunset.

$location->sunset(); // returns an instance of \DateTimeImmutable

You can get the time of the sunset on a specific date by passing an object which implements DateTimeInterface to sunset

If the object extends DateTimeImmutable the return object will be of the same type.

$carbon = CarbonImmutable::now();

$location->sunset($carbon); // returns an instance of \Carbon\CarbonImmutable

If no sunset information is available for a specific geolocation null is returned.

Determine if the sun is up

This is how you can determine if the sun is up:

$location->isSunUp(); // returns a boolean

You can get determine if the sun is up at a specific moment by passing an instance of DateTimeInterface to sunIsUp

$carbon = Carbon::now();

$location->sunIsUp($carbon); // returns a boolean

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages