This package uses geolocation to determine several properties around the sun position.
This package is a fork of Spatie/Sun
You can install the package via composer:
composer require bakame-php/geolocationTo 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.0or above90.0degrees are capped, not wrapped. - Longitudes below
-180.0or above180.0degrees 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);You can get the time of the zenith.
$location->zenith(); // returns an instance of \DateTimeImmutableYou 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\CarbonImmutableYou can get the time of the sunrise.
$location->sunrise(); // returns an instance of \DateTimeImmutableYou 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\CarbonImmutableIf no sunrise information is available for a specific geolocation null is returned.
You can get the time of the sunset.
$location->sunset(); // returns an instance of \DateTimeImmutableYou 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\CarbonImmutableIf no sunset information is available for a specific geolocation null is returned.
This is how you can determine if the sun is up:
$location->isSunUp(); // returns a booleanYou 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 booleancomposer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.